Skip to content

Latest commit

 

History

History
28 lines (14 loc) · 457 Bytes

31_Java9_new_Features.md

File metadata and controls

28 lines (14 loc) · 457 Bytes

Factory Methods for Collections

Java7

List myList = new ArrayList();

Java8 自动类型推断

List myList = new ArrayList<>(); myList.add(new Point(1, 1)); myList.add(new Point(2, 2)); myList.add(new Point(3, 3)); myList.add(new Point(4, 4)); myList = Collections.unmodifiableList(myList);

Java9 不可变List

List list = List.of(new Point(1, 1), new Point(2, 2), new Point(3, 3), new Point(4, 4));