import java.util.List;
import java.util.Map;
import java.util.Set;
public class DemoJDK9 {
public static void main(String[] args) {
Set<Integer> one = Set.of(1,2,3,4);
System.out.println(one);
List<Integer> two = List.of(1,2,3,4);
System.out.println(two);
Map<String,Integer> three = Map.of("a",1,"b",2,"c",3);
System.out.println(three);
}
}
异常
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DemoJDK9 {
public static void main(String[] args) {
Set<Integer> one = Set.of(1, 2, 3, 1);
元素重复 IllegalArgumentException
List<Integer> two = List.of(1, 2, 3, 1);
two.add(6);
返回值不能改 UnsupportedOperationException
Map<String, Integer> three = Map.of("a", 1, "a", 2, "c", 3);
元素重复 IllegalArgumentException
}
}