泛型与异常

就像ArrayList list=new ArrayList();

利用泛型ArrayList<Integer> list=new ArrayList<>();

类名<Integer> list=new 类名<>(1);

class 类名<T>{

private T o;

public 类名(T o){

  this.o=o;

  }

public void showTypeName(){

  System.out.println(o.getClass.getName());//反射机制

}

}

使用泛型的好处:

1.类型安全;

2.向后兼容;

3,层次清楚;

4,性能较高;

 

以下的情况,finally中的语句不会被执行:

1,finally块中发生异常;

2。程序所在线程死亡;

3.在前边的代码块中出现exit(0);

4.关闭cpu;

posted @ 2015-12-29 14:24  戒。  阅读(60)  评论(0编辑  收藏  举报