Community
Participate
Working Groups
In the following pieve of code I get the error "The return type is incompatible with DoubleHash<Term,Term,Relation>.create()". How can it be incompatble if it is a static method and as such does not override any method? public class HashOrder extends DoubleHash<Term,Term,Relation> { private HashOrder() { } /** Creates a new instance of <code>HashOrder</code>. */ public static HashOrder create() { return new HashOrder(); } } FYI: DoubleHash has a declaration as follows: /** Creates a new instance of <code>DoubleHash</code>. */ public static <W,X,Y> DoubleHash<W,X,Y> create() { return new DoubleHash<W,X,Y>(); }
javac returns only a warning: X.java:8: warning: create() in X overrides <W,X,Y>create() in DoubleHash; return type requires unchecked conversion found : X required: DoubleHash<W,X,Y> public static X create() { ^ 1 warning
Fix will not be ready for 3.1.1, removing target milestone "3.1.1"
This is the same problem as bug 125956. Static methods can 'override' inherited static methods, see the example below. The problem is with the inherited method defining its own type variables but the subclass' method remaining as is. For backwards compatibility, the compiler should issue a conversion check warning instead of an error, until the subclass' method adds the necessary type variables. The error/warnings are the same even when the methods are not static. class Z<T> extends ZZ<T> { static @Override A<?> foo() {return null;} // unchecked converion warning static @Override A<String> bar() {return null;}// unchecked converion warning static <S> A<String> baz() { return null; } // actual return type error } class ZZ<TT> { static <T> A<T> foo() { return null; } static <V> A<V> bar() { return null; } static <U> A<U> baz() { return null; } } class A<T> {} *** This bug has been marked as a duplicate of 125956 ***
Added MethodVerify test80