Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
SYNOPSIS Valid generic types leading to compilation problems. OPERATING SYSTEM(S) All Platforms. FULL JDK VERSION(S) Seen on all releases of Java 5.0, Java 5.0, Java 6.0 and Java 7.0 PROBLEM DESCRIPTION javac fails to compile these below given valid generic classes. TESTCASE: Case-1: public class TestGeneric2<T extends Comparable<? super T>> { public void test(T v) { Object obj = v; if (v instanceof Integer) { obj = Long.valueOf(((Integer) v).longValue()); } System.out.println(obj.getClass().getName()); } } Case-2: public class TestGeneric3<T extends Comparable<? extends T>> { public void test(T v) { Object obj = v; if (v instanceof Integer) { obj = Long.valueOf(((Integer) v).longValue()); } System.out.println(obj.getClass().getName()); } } REPRODUCTION INSTRUCTIONS javac fails to compile the above two cases. FAILURE OUTPUT /* Sun Java 1.5 and 1.6 gives TestGeneric2.java:4: inconvertible types found : T required: java.lang.Integer if (v instanceof Integer) { ^ TestGeneric2.java:5: inconvertible types found : T required: java.lang.Integer obj = Long.valueOf(((Integer) v).longValue()); ^ 2 errors */ javac compiles when the above generic classes are defined as "TestGeneric2<T extends Comparable<?>>"
|