| Summary: | Compiler compliance level has no effect | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Andrew Mak <makandre> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED INVALID | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 3.3 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
The compiler is using the libraries on the classpath to know what methods are available. There is no clue that the getSimpleName() method exists only since 1.5. If you want to run on a 1.4 VM, you better put a 1.4 library on your classpath. The compliance has nothing to do with checking the methods used in the code. Ok to close? So what exactly does the compliance level setting give me? The compliance level means that it behaves like the javac of the same level. So compliance 1.5 means javac 1.5, compliance 1.4 javac 1.4, ... So the compliance will set the values for the source and target platform levels. It doesn't change or check the libraries on the classpath. If you do the same steps with javac, you get the same error. from javac 1.5, javac test\MyClass -target 1.4 -source 1.4 and then from a 1.4 VM: java test.MyClass This will report the same error. Thanks for clarifying the use of that setting. Yes, OK to close. Working as designed. Closing. Closing. |
I'm running eclipse 3.3M7 with a 1.5 level jdk. In my workspace, I create a Java project (leaving the JRE at the default 1.5 level). Then I change the project specific properties and set the compiler compliance level to 1.4. I create the following class: package test; public class MyClass { public static void main(String[] args) { System.out.println(MyClass.class.getSimpleName()); } } Note that Class.getSimpleName() is a 1.5 method, so I expected to get some warning or error about it but I didn't get any. And when I run this app using java 1.4 I will get an error: Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Class: method getSimpleName()Ljava/lang/String; not found at test.MyClass.main(MyClass.java:6)