Community
Participate
Working Groups
This snippet: public <T extends Object> void foo(T x) { Class<? extends T> c = x.getClass(); } ... compiles fine in 3.2, but under 3.2.1 it's flagged with the following error: Type mismatch: cannot convert from Class<capture-of ? extends Object> to Class<? extends T> The tooltip for x.getClass() also indicates that it returns a Class<? extends Object>, which is incorrect. Under 3.2 it returns Class<? extends T>, which is correct.
Actually, we were wrong in 3.2.0. We fixed this since then, also see bug 147381. btw javac agrees with us: X.java:3: incompatible types found : java.lang.Class<capture#297 of ? extends java.lang.Object> required: java.lang.Class<? extends T> Class<? extends T> c = x.getClass(); ^ 1 error Closing
Upon reviewing the documentation in Object.getClass(), it's also my interpretation that the new behavior (in 3.2.1) is correct. "The result is of type {@code Class<? extends X>} where X is the erasure of the static type of the expression on which <code>getClass</code> is called." In this case, the erasure of T would be Object, so the resulting type would be Class<? extends Object>, as it is in 3.2.1.
Changing OS from Mac OS to Mac OS X as per bug 185991