Community
Participate
Working Groups
The code below gives forth this compilation error, but javac is OK with it: clash: The method error(Collection<String>) of type Parent.Child has the same erasure as error(Collection) of type Parent but does not override it *********** Parent.java ************* import java.util.Collection; public class Parent { public static void error (Collection c){ } public static class Child extends Parent { public static void error(Collection<String> c) { } } }
I don't know if it's the same root, but an error also happens when using @Override with static methods. This code has both conditions: import java.util.Collection; public class Parent { public static void error (Collection c){} public static void error2 () {} public static class Child extends Parent { public static void error(Collection<String> c) {} @Override public static void error2() {} } }
Reproduced first problem in latest. Second issue is expected behavior. Static methods are not overriding. Javac1.6 says: X.java:9: method does not override a method from its superclass @Override public static void error2() {} ^ 1 error
We should not detect name clashes between inherited static methods. The following case shows that the instance methods do cause a name clash: import java.util.Collection; class Parent { static void staticCase1(Collection c) {} static void staticCase2(Collection<String> c) {} void instanceCase1(Collection c) {} void instanceCase2(Collection<String> c) {} } class Child extends Parent { static void staticCase1(Collection<String> c) {} static void staticCase2(Collection c) {} // @Override is an error for instanceCase1 // name clash: instanceCase1(Collection<String>) in Child and // instanceCase1(Collection) in Parent have the same erasure, yet // neither overrides the other void instanceCase1(Collection<String> c) {} @Override void instanceCase2(Collection c) {} } case2 is allowed for compatibility reasons, but case1 is a name clash.
Added MethodVerifyTest 85
Verified with I20060427-1600 for 3.2RC2