Bug 58666 - [1.5] Object.getClass() need to be treated special ?
Summary: [1.5] Object.getClass() need to be treated special ?
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-15 11:27 EDT by Philipe Mulet CLA
Modified: 2005-01-11 11:02 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2004-04-15 11:27:05 EDT
Cheetah02

The following program is demonstrating a curious behavior in Javac:

public class X { 
    public static void main(String[] args) {
		X x = new X();
		Class<? extends X> c1 = x.getClass();  // OK
		String s = "hello";
		Class<? extends X> c2 = s.getClass();  // KO
    }
}

X.java:6: incompatible types
found   : java.lang.Class<? extends java.lang.String>
required: java.lang.Class<? extends X>
                Class<? extends X> c2 = s.getClass();
                                                  ^
1 error


Officially the type of Object.getClass() is:  Class<? extends Object>.
It seems that the compiler is automatically transforming it into: Class<? 
extends X> for the invocation of x.getClass(). This is what is exposed by the 
subsequent invocation with a String...

Is Object#getClass() specially handled by the compiler ?
Comment 1 Philipe Mulet CLA 2004-04-15 11:27:51 EDT
See javac related bug: 
http://developer.java.sun.com/developer/bugParade/bugs/5004321.html
Comment 2 Philipe Mulet CLA 2004-04-15 16:57:34 EDT
Added regression tests: GenericTypeTest#test128&129.
Comment 3 Philipe Mulet CLA 2004-04-15 16:58:06 EDT
Fixed.