class Jls7error<T extends OutputStream> {
class Jls7errorInner<S extends T> {
public S out;
}
}根据jls7 Oracle文档,此代码不应编译:
引用泛型类C的类型参数是编译时错误。·C中嵌套的任何类。
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.1.2
(pag 185,docs.oracle.com/javase/specs/jls/se7/jls7.pdf)
实际上,这段代码确实在我的JDK1.7上编译和运行,是文档错误吗?
编辑:这是PDF版本中的文档错误。Oracle更正了html和pdf文档中的文档。
发布于 2012-09-08 20:43:35
我不知道你在哪里看到any class nested within C。那部分实际上是说
引用泛型类C中任何位置的类型参数都是编译时错误:
这里有一个例子来演示每一颗子弹都不允许的是什么:
public class Foo<T> {
private static T t; // first bullet makes this a compiler error
static {
T t; // third bullet makes this a compiler error
}
private static class Bar {
private static T t; // second bullet makes this a compiler error
static {
T t; // fourth bullet makes this a compiler error
}
}
private class Baz {
private static T t; // second bullet again
// you can't have a static initializer
// in a non-static nested class
}
}发布于 2012-09-08 20:43:48
(移动到回答空格/格式设置)。
唯一提到这一点的地方是:
引用泛型类C中任何位置的类型参数都是编译时错误:
https://stackoverflow.com/questions/12334159
复制相似问题