import java.util.List; public class Demo06Tips { public static void main(String[] args) { try { List<Integer> list = List.of(1, 2, 3); System. out. println(list.get(3)); } catch(IndexOutOfBoundsException e){ System.out. println(e); } } }
执行的结果是:java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
老师的执行结果是:java.lang.IndexOutOfBoundsException: Index 3 out of bounds for length 3
暂时得出:List.of()返回的不是一个ArrayList,而是一个不可变的List
有大佬知道具体的原因,请告诉我,先感谢了
此处get源码图:

浙公网安备 33010602011771号