私が次のことをすると、
arrayList1- 1 つの要素を含み、int[].arrayList2- コンパイルしていません (エラー: コンストラクターArrayList<Integer>(List<int[]>)が未定義です)arrayList3- 7 つの要素を含み、それらはIntegerオブジェクトです
コードは次のとおりです。
int[] intArray = new int[]{2,3,4,5,6,7,8};
ArrayList arrayList1 = new ArrayList(Arrays.asList(intArray));
ArrayList<Integer> arrayList2 = new ArrayList<Integer>(Arrays.asList(intArray));
Integer[] integerArray = new Integer[]{2,3,4,5,6,7,8};
ArrayList<Integer> arrayList3 = new ArrayList<Integer>(Arrays.asList(integerArray));
質問 :int[]コンパイラがto 内の要素を自動ボックス化してIntegerを作成
しないのはなぜArrayList<Integer>ですか? この背後にある理由は何ですか? それは私の愚かさですか、それとも他の理由ですか?