Bug 159818

Summary: [1.5] [compiler] genericized getClass() return type is incorrect
Product: [Eclipse Project] JDT Reporter: Tom Crockett <Thomas.M.Crockett>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2.1   
Target Milestone: 3.3 M3   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Tom Crockett CLA 2006-10-04 18:09:04 EDT
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.
Comment 1 Philipe Mulet CLA 2006-10-05 04:52:14 EDT
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
Comment 2 Andrew Bachmann CLA 2006-10-05 16:51:09 EDT
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.
Comment 3 Eclipse Webmaster CLA 2007-07-29 09:20:58 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991