for code
import java.util.*;
interface Sample{
}
public class TypeTest implements Sample{
public static void main(String[] args) {
Set<Object> objs = new HashSet<>();
objs.add(new TypeTest());
List<? extends Sample> objList = (List<? extends Sample>) new ArrayList<>(objs);
for (Sample t : objList) {
System.out.println(t.toString());
}
}
}
it can run in eclipse and output TypeTest@7852e922
but javac
will get an error:
incompatible types: ArrayList<Object> cannot be converted to List<? extends Sample>