Weird usage of Java Generics compiles correctly with JDT (and code runs) but does not compile with Oracle's Java6 compiler
Danilo Tommasina
danilo.tommasina at avanon.com
Tue Feb 21 05:49:52 PST 2012
Hi Maurizio
Many thanks for the quick reply.
Best Regards
Danilo
On 02/21/2012 02:32 PM, Maurizio Cimadamore wrote:
> Hi
> These failures are caused by the fact that JDK 6 compiler doesn't
> implement type-inference correctly. A lot of effort has been put into
> JDK 7 compiler in order to get rid of all these problems (your program
> compiles fine in JDK 7). However, some of those inference improvements
> require source incompatible changes, which is why we cannot backport
> these fixes in the JDK 6 release.
>
> Maurizio
>
> On 21/02/12 12:43, Danilo Tommasina wrote:
>> |class MyWeirdClass {
>>
>> public void entryPoint() {
>> doSomethingWeird();
>> }
>>
>> @SuppressWarnings( "unchecked" )
>> private <Textends A& B> T getMyClass() {
>> if ( System.currentTimeMillis() % 2 == 0 ) {
>> return (T) new MyClass_1();
>> } else {
>> return (T) new MyClass_2();
>> }
>> }
>>
>> private <Textends A& B> void doSomethingWeird() {
>> T obj= getMyClass();
>>
>> obj.methodFromA();
>> obj.methodFromB();
>> }
>>
>> static interface A{
>> void methodFromA();
>> }
>>
>> static interface B{
>> void methodFromB();
>> }
>>
>> static class MyClass_1 implements A, B{
>> public void methodFromA() {};
>> public void methodFromB() {};
>> }
>>
>> static class MyClass_2 implements A, B{
>> public void methodFromA() {};
>> public void methodFromB() {};
>> }
>> }
>> |
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20120221/e0e9cda7/attachment.html
More information about the compiler-dev
mailing list