我们已经开始在使用泛型的代码上编译错误,并且在Java 6下成功编译.这是一个简单的类来重现:
class Test {
static class Foo<T> {
T t;
Foo(T t) { this.t = t; }
T get() { return t; }
}
static class Bar extends Foo<Long> {
Bar(Long t) { super(t); }
}
static class Foobar<N extends Number> extends Bar {
Foobar() { super(5L); }
}
public static void main(String[] args) {
Bar bar = new Bar(0L);
Long b = bar.get(); // This works
Foobar foobar = new Foobar();
Long fb = foobar.get(); // This generates …Run Code Online (Sandbox Code Playgroud)