노무현 전 대통령 서거 추모글 남기기

'2018/10'에 해당되는 글 1건

  1. 2018.10.31 ArrayList<Stri ng>[] temp Generic array creation error 1

ArrayList 의 구조를 가지고 있는 배열을 쓰기..


검색해보니까 ArrayList 를 배열로 바꾸는 것만 잔뜩있고 아니면 ArrayList<Stri ng[]> 이런 구조 얘기만 있고해서 헤메고 있었다..


그러다 얻게 된 해결책


https://stackoverflow.com/questions/7131652/generic-array-creation-error/23034391


링크에 좋아요 엄청받은 것을 적용해 보았더니 안된다..


두번째


First, let

public static ArrayList<myObject>[] a = new ArrayList[2];

Then initialize

for(int i = 0; i < a.length; i++) {
     a[i] = new ArrayList<myObject>();
}

이렇게 하니까 잘된다.


세번째는 선언하는 방식만 변경이 있을 뿐 초기화는 어짜피 따로 해줘야 동작하더라..


public static ArrayList<myObject>[] a = (ArrayList<myObject>[])new ArrayList<?>[2];
public static ArrayList<myObject>[] a = (ArrayList<myObject>[])new ArrayList[2];


Posted by Kelly Cook
,