Bug 106880 - [1.5][compiler] Incompatible return type on static method
Summary: [1.5][compiler] Incompatible return type on static method
Status: RESOLVED DUPLICATE of bug 125956
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-12 13:58 EDT by Eric Bodden CLA
Modified: 2006-02-24 13:16 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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