Hi,
I upgraded to Eclipse Oxygen yesterday and as soon as I fired up my workspace JDT complained about some code in it. That code compiles fine with Eclipse Neon (JDT 3.12.3) and Oracle Java 8 JDK. I also upgraded my Oracle JDK to 8 update 161 (latest Java 8 version) and it still seems to think that there are no issues with the code that Oxygen is offended by.
I was about to file a bug report and trimmed the it down to this snippet which reproduces the problem:
package playground;
public class EclipseOxygen
{
public <T, E extends T> EclipseOxygen(E impl, Class<T> intf) {
}
public <T, E extends T> void andAsMethod(E impl, Class<T> intf) {
}
public <T> void something(T ref) {
@SuppressWarnings("unchecked")
Class<? super T> clazz = (Class<? super T>) ref.getClass();
new EclipseOxygen(ref, clazz.asSubclass(EclipseOxygen.class));
andAsMethod(ref, clazz.asSubclass(EclipseOxygen.class));
}
}
Oxygen cries foul when invoking the constructor:
The constructor EclipseOxygen(T,Class<capture#4-of ? extends EclipseOxygen) is undefined
Same error two lines below in the method invocation.
The snippet though made it apparent to me that T is obviously unrelated (in terms of bounds) to class EclipseOxygen so it seems to me that Oxygen's JDT is actually right? I fixed it with casting ref to that class:
package playground;
public class EclipseOxygen
{
public <T, E extends T> EclipseOxygen(E impl, Class<T> intf) {
}
public <T, E extends T> void andAsMethod(E impl, Class<T> intf) {
}
public <T> void something(T ref) {
@SuppressWarnings("unchecked")
Class<? super T> clazz = (Class<? super T>) ref.getClass();
new EclipseOxygen((EclipseOxygen)ref, clazz.asSubclass(EclipseOxygen.class));
andAsMethod((EclipseOxygen)ref, clazz.asSubclass(EclipseOxygen.class));
}
}
It seems that the Class<? super T> confuses Eclipse Neon and Oracle JDK and this is a bug in both (now fixed in Oxygen)?