The code below compiles without any error with Eclipse but generates an error with Javac. It seems to be a compiler error but I don't know which one is right.
I would like to point out that I know how to correct this error by changing the code to make it work with both, but that is not the current topic. I would just like to know whether it's a java or an eclipse problem.
I try with Intellij but I have the same javac error.
Sample code to reproduce this error:
import java.util.ArrayList;
import java.util.List;
public class A<T extends B> {
protected List<C> list = new ArrayList<>();
class C {}
public void createIO() {
A<? extends B> x = null;
List<A<? extends B>.C> y = x.list;
}
}
class B {
}
JVM:
openjdk version "13-BellSoft" 2019-09-17
OpenJDK Runtime Environment (build 13-BellSoft+33)
OpenJDK 64-Bit Server VM (build 13-BellSoft+33, mixed mode, sharing)
With Eclipse, I don't have any errors. With Javac, I have the error:
A.java:13: error: incompatible types: List<A<CAP#1>.C> cannot be converted to List<A<? extends B>.C>
List<A<? extends B>.C> y = x.list;
^
where CAP#1 is a fresh type-variable:
CAP#1 extends B from capture of ? extends B