Bug 159818 - [1.5] [compiler] genericized getClass() return type is incorrect
Summary: [1.5] [compiler] genericized getClass() return type is incorrect
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.3 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-04 18:09 EDT by Tom Crockett CLA
Modified: 2007-07-29 09:20 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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