类(class)的类型形参的作用范围是整个class,除了静态(static)成员和静态初始化模块.
class Test <T> {
//类型形参的写法
static {
Test<T> test = new Test<T>(); // error static initializer
}
private static T field; // error static field
public static T method() {
// error static method
}
public T method2(){
} // right 正确
}
参考:
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeParameters.html#FAQ301