| Summary: | [1.5][compiler] Casting to an inner class with generics compiles in Eclipse, but fails in javac | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | fahdshariff |
| Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> |
| Status: | VERIFIED NOT_ECLIPSE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | fahdshariff, Olivier_Thomann |
| Version: | 3.6 | ||
| Target Milestone: | 3.7 M5 | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
This is a bug in the javac compiler that has since been fixed. JDK 7b100 compiles this fine. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6665356 Verified for 3.7M5 using I20110124-1800 |
Build Identifier: M20100211-1343 Consider the following code: public class Outer<T> { public class Inner{ } public static <T> Outer<T>.Inner get(){ Object o = new Object(); return (Outer<T>.Inner)o; } public static void main(String[] args) throws Exception { Outer.<String>get(); } } This code compiles successfully in Eclipse, but fails to compile in javac (1.6.0_21): Outer.java:10: ')' expected return (Outer<T>.Inner)o; ^ Outer.java:10: ';' expected return (Outer<T>.Inner)o; ^ Outer.java:10: illegal start of expression return (Outer<T>.Inner)o; ^ 3 errors Is this a bug in javac or Eclipse? If I change the cast to (Outer.Inner)o it compiles, although there is a warning: Eclipse: Outer.Inner is a raw type. References to generic type Outer<T>.Inner should be parameterized javac: Outer.java:10: warning: [unchecked] unchecked conversion found : Outer.Inner required: Outer<T>.Inner return (Outer.Inner)o; ^ 1 warning Reproducible: Always Steps to Reproduce: 1. Create a class called Outer with the following code: public class Outer<T> { public class Inner{ } public static <T> Outer<T>.Inner get(){ Object o = new Object(); return (Outer<T>.Inner)o; } public static void main(String[] args) throws Exception { Outer.<String>get(); } } 2. Compile with javac using the command: javac Outer.java You will see that javac will report problems, whereas Eclipse doesn't.