Possible Duplicate:
Generics compiles and runs in Eclipse, but doesn't compile in javac
Compilers behave differently with a null parameter of a generic method
public static void main(String[] args) {
Class<Object> type1 = String.class;
Class<? extends Object> type2 = String.class;
Class<Object> type3 = get(String.class);
Class<Object> type4 = Foo.<Object, String> get(String.class);
}
public static <I, C extends I> Class<I> get(Class<C> type) {
return null;
}
The first line will generate the following compilation error:
Type mismatch: cannot convert from
Class<String>
toClass<Object>
which is pretty much normal. The second line will work fine.
The third line works differently when compiling in eclipse and in javac. Eclipse will compile happily. Javac will give me the following error:
[ERROR] Foo.java:[36,26] incompatible types
[ERROR] found : java.lang.Class<java.lang.String>
[ERROR] required: java.lang.Class<java.lang.Object>
The forth line compiles correctly in both compilers.
Can anyone explain what is happening? Thank you :)