Bug 106880

Summary: [1.5][compiler] Incompatible return type on static method
Product: [Eclipse Project] JDT Reporter: Eric Bodden <eric>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: RESOLVED DUPLICATE QA Contact:
Severity: major    
Priority: P3 CC: mlists
Version: 3.1   
Target Milestone: 3.2 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Eric Bodden CLA 2005-08-12 13:58:24 EDT
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>();
    }
Comment 1 Olivier Thomann CLA 2005-08-12 14:32:42 EDT
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
Comment 2 Philipe Mulet CLA 2005-09-23 06:18:44 EDT
Fix will not be ready for 3.1.1, removing target milestone "3.1.1"
Comment 3 Kent Johnson CLA 2006-02-23 11:23:40 EST
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 ***
Comment 4 Kent Johnson CLA 2006-02-23 13:05:33 EST
Added MethodVerify test80