jdk8新特性(附jdk5/jdk6/jdk7新特性)

https://blog..net/ydk888888/article/details/78630492

Java5:

1、泛型 Generics: 引用泛型之后,允许指定集合里元素的类型,免去了强制类型转换,并且能在编译时刻进行类型检查的好处。

Parameterized Type作为参数和返回值,Generic是vararg、annotation、enumeration、collection的基石。

A、类型安全

            抛弃List、Map,使用List<T>、Map<K,V>给它们添加元素或者使用Iterator<T>遍历时,编译期就可以给你检查出类型错误

B、方法参数和返回值加上了Type

抛弃List、Map,使用List<T>、Map<K,V>

C、不需要类型转换

List<String> list=new ArrayList<String>();

String str=list.get(i);

          D、类型通配符“?”

假设一个打印List<T>中元素的方法printList,我们希望任何类型T的List<T>都可以被打印

经验分享 程序员 微信小程序 职场和发展