jdk10
局部变量类型推断
public class TenTest {
@Test
public void t1() {
var num = 10;
var list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
for (var i : list) {
System.out.println(i);
}
}
@Test
public void t2(){
Supplier<Double> supplier = ()->Math.random();
Consumer<String> consumer = System.out::println;
int[] arr = {1,2,3,4};
}
}
copyOf()
@Test
public void t4(){
var list1 = List.of(1,2,3);
var list2 = List.copyOf(list1);
System.out.println(list1 == list2);
var list3 = new ArrayList<String>();
var list4= List.copyOf(list3);
System.out.println(list3==list4);
}