Community
Participate
Working Groups
The folloging code compiles with eclipse, but generates an error with JDK 1.5 public class CompareAtomicClasses<S extends Comparable<S>> { public void f() { Class<S> currentClass = null; boolean b = currentClass == Long.class; } } JDK1.5 (1.5 Update 2) says: incomparable types: java.lang.Class<S> and java.lang.Class<java.lang.Long> ciao Volker
Reproduce with M6.
Class<S> is not provably distinct from Class<Long>, so I would say we are right and javac is wrong according to JLS 5.5 (casting) and JLS 4.5 (provably distinct). So it is different from comparing: Class<String> and Class<Long> as these are provably distinct.
Maybe you should report this to javac buglist. Added GenericTypeTest#test588.
Based on discussion with Java spec lead, this is an area where the spec is going to become stricter. So the rules for probable distinctness are going to evolve to take bounds into accounts for wildcard/intersectionTypes/type parameters. Note that javac seems to do some of it already. Reopening to investigate alignment there.
Current discussions would confirm that Class<S> and Class<Long> are not provably distinct. Hence javac would be wrong.
See also bug 95066
Closing as INVALID. Our behavior is actually correct. Released some changes near cast conversion, as part of fix for bug 158870. But the scenario reported here remains unchanged.
Verified for 3.4 M3 using build I20071029-0010.