JDK-5049523 : Inference should compute glb of type arguments
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2004-05-19
  • Updated: 2006-03-15
  • Resolved: 2006-02-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b71Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
from http://forum.java.sun.com/thread.jsp?forum=316&thread=523496

I have changed the code to make it compile:

abstract class Test {

    protected <T> void getConstructor(Class<? extends T> clazz) {
        Class<? extends T> impl;
        impl = clazz.isInterface() ? getImplementationClass(clazz) : clazz;
        if (clazz.isInterface()) {
            impl = getImplementationClass(clazz);
        } else {
            impl = clazz;
        }
    }


    abstract public <T> Class<? extends T>
    getImplementationClass(Class<T> interfaceClass);
}

This line don't compile in tiger-fcs, but compiled in b48:

impl = clazz.isInterface() ? getImplementationClass(clazz) : clazz;
###@###.### 10/27/04 01:05 GMT

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/langtools_data/mustang/5049523
28-12-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
07-09-2004

EVALUATION Possibly a bug. ###@###.### 2004-05-18 Is a bug, JLS requires that the greatest lower bound (glb) of the type arguments must be computed. The problem is a shortcoming of inference, the example below demonstrates it using both a conditional expression and a generic method: ===== T5049523.java: public class T5049523 { static <T> T choose(boolean b, T t1, T t2) { return b ? t1 : t2; } protected <T> Class<? extends T> m1(Class<? extends T> clazz) { Class<? extends T> impl; boolean b = clazz.isInterface(); impl = b ? m2(clazz) : clazz; // shouldn't fail impl = choose(b, m2(clazz), clazz); // shouldn't fail if (b) { impl = m2(clazz); } else { impl = clazz; } return impl; } public <T> Class<? extends T> m2(Class<T> c) { return c; } } ===== ###@###.### 2004-05-21
21-05-2004