JDK5.0的11个主要新特征[6]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

                     ioe.printStackTrace();

              }

       }

}

1.5          泛型的通配符"?"

"?"可以用来代替任何类型, 例如使用通配符来实现print方法。

public static void print(GenList<?> list) {})

1.6          泛型的一些局限型

不能实例化泛型

T t = new T(); //error

不能实例化泛型类型的数组

T[] ts= new T[10];   //编译错误

不能实例化泛型参数数

Pair<String>[] table = new Pair<String>(10); // ERROR

类的静态变量不能声明为类型参数类型

public class GenClass<T> {

     private static T t;    //编译错误

}

泛型类不能继承自Throwable以及其子类

public GenExpection<T> extends Exception{}    //编译错误

不能用于基础类型int

Pair<double> //error

本文关键:JDK5.0的11个主要新特征
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top