Community
Participate
Working Groups
The following code compiles fine with Eclipse: package test; public class One { public static void arrayList() { } } Separate file: package test; import static test.One.arrayList; class Two { public static void arrayList(int x) { arrayList(); } } With javac, it reports: $ javac test/*.java test/testcase.java:9: arrayList(int) in test.Two cannot be applied to () arrayList(); ^ While I prefer the Eclipse behaviour, I'd like to retain source compatibility with Java. Testers report that RC4 and RC5 exhibit this behaviour - I experienced it myself with 3.2M5.
I meant RC3 and 4, as 5 isn't actually available at the time of submitting this bug. I misread sarcasm on the part of the tester!
This bug has already been reported against javac, and closed because the specification says it's the correct behaviour. I cannot find where that is true in the Java Language Specification. The relevant bug report is here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5085373
Thanks for the report
From JLS spec team: http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.3.1 "A declaration d of a method named n shadows the declarations of any other methods named n that are in an enclosing scope at the point where d occurs throughout the scope of d." This means that the declaration of arrayList(int) shadows the one that is imported.
Added StaticImport test45 Released change to Scope.getImplicitMethod into 3.2.1 branch
Released for 3.2.1 Released for 3.3 M1 while merging TARGET_321 in HEAD
I believe this is not fixed: package test; public class One{ public static void arrayList(String s){} } Separate file: package test; class Two{ public void arrayList(int x){} } Separate file: package test; import static test.One.arrayList; class Three extends Two{ public static void aMethod(){ arrayList("s"); //Compiles fine under eclipse, but not javac } }
I reproduced Stephen Kestle's results, and am therefore reopening this bug.
Which build are you using? I tried this with the latest from HEAD and the 3.2.1 branch, and they both report the same error as javac.
Added additional cases as StaticImport test45b
My build id is M20060629-1905, and the core jdt 3.2.1.z20060711-1626. Kent, just in case you missed it, the problem was that the static import of class Three was being shadowed by the method in the super-class Two.
Verified for 3.3 M1 using build I20060807-0010.
Verified for 3.2.1 using build M20060908-1655. Note that Three.java comment 7 test case does not compile in Eclipse neither in 3.2 nor in 3.2.1...