Bug 58666

Summary: [1.5] Object.getClass() need to be treated special ?
Product: [Eclipse Project] JDT Reporter: Philipe Mulet <philippe_mulet>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.0   
Target Milestone: 3.1 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

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.