Source / Target flag Compiling

Hey Everyone,

Right now I’ve got Java 1.5 SDK on my computer. I wanted to compile for 1.3, so I did this:

javac -source 1.3 -target 1.3 *.java

It successfully compiled without giving any errors.

However, the program didn’t run. Why?

Because I called the String.contains(String) method, which wasn’t introduced until 1.4.

Why doesn’t it catch this?

Thanks.

-target 1.x makes the bytecode compatible with prior 1.5 bytecode standard. It does not check if you are using individiual methods that has been introduced later than your target flag.

[quote]-target 1.x makes the bytecode compatible with prior 1.5 bytecode standard. It does not check if you are using individiual methods that has been introduced later than your target flag.
[/quote]
For this to happen you need specifiy the switch “bootclasspath” (I think) with the rt.jar (?) of the old version.

I think we did this a long time ago at work, but can’t remember the details anymore.