泛型!

指定了参数类型编译器在编译期间就会帮助你检查存入容器的对象是不是参数类型!不是就会报错!保证了类型安全!性能上没什么影响,因为泛型在运行期间会擦除!就是说用不用类型参数在运行期间编译后的运行代码是一样的!
Map map = new HashMap();
Map<String,String> map1 =new  HashMap<String,String>();
System.out.println(map.getClass().equals(map1.getClass()));返回结果会true;说明他们运行的是同一份字节码!

猜你喜欢

转载自cainiao1923.iteye.com/blog/2357225