Weird usage of Java Generics compiles correctly with JDT (and code runs) but does not compile with Oracle's Java6 compiler
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Feb 21 05:32:14 PST 2012
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/d891246c/attachment.html
More information about the compiler-dev
mailing list