Stream.toList()도 UnmodifiableList 어쩌구긴 한데 결국 List 아냐?
댓글 16
그걸 알아가는게 코딩임
익명(39.7)2023-01-06 02:37
답글
이건뭐 어떻게 찾아야될지도 모르겠다
익명(221.142)2023-01-06 02:39
답글
자바 도큐 가면 라이브러리 함수에 대한 설명 다 나와있음
익명(39.7)2023-01-06 02:39
toList를 해버리면 List[ArrayList] 이게 나오고
collect를 하면 List[List[Integer]] 이게 나와요
걍 잘못된 메서드를 호출한거
김대기(waitkim)2023-01-06 02:39
답글
김대기 속꽉찬 실수였노 ㅋㅋ
익명(110.10)2023-01-06 02:40
답글
ArrayList도 List 변수에 넣을 수 있는거 아님..? 1차원 리스트는 되던데
익명(221.142)2023-01-06 02:40
답글
List[List[Integer]] arr2 = Stream.generate(() -> new ArrayList()).limit(10).collect(Collectors.toList());
List[List[Integer]] arr3 = Stream.generate(() -> new ArrayList()).flatMap(list - list.stream()).limit(10).toList();
김대기(waitkim)2023-01-06 02:40
답글
할거면 이렇게 해야징
김대기(waitkim)2023-01-06 02:41
답글
와 오지네... 코드 분석해보고 공부좀해야겠다 존나 고마움
익명(221.142)2023-01-06 02:42
답글
님이 원하는걸 하려면 이렇게 해야함
제네릭 공부좀 해야될듯
List[List[Integer]] arr2 = Stream.generate(() - new ArrayList()).limit(10).collect(Collectors.toList());
List[? extends List] arr3 = Stream.generate(() - new ArrayList()).limit(10).toList();
김대기(waitkim)2023-01-06 02:44
답글
뭐지 ㅋㅋㅋ 내가보기엔 List[List]랑 List[? extends List]랑 똑같아 보이는데 아직 흐접이라 그런거겠지? ㅠㅠ 방향 잡아줘서 감사
익명(221.142)2023-01-06 02:49
답글
어 근데 자세히 보니까 위쪽 코드도 문법 오류만 안난다 뿐이지 런타임 에러가 나는 코드임
애초에 new ArrayList()만 했는데 타입이 추론될수가 없어가지고;;
이렇게 하셈
List[List[Integer]] arr2 = Stream.generate(() -> new ArrayList()).limit(10).collect(Collectors.toList());
List[ArrayList[Integer]] arr3 = Stream.generate(() -> new ArrayList()).limit(10).toList();
김대기(waitkim)2023-01-06 02:51
답글
오.. 김대기 빈수레 아니었구나
로비123(hyunjae1114)2023-01-06 02:54
답글
궁금한게 그부분인데 List[List] arr = List.of(new ArrayList(), new ArrayList()); 같은건 되는데 왜 Stream.toList() 쓰면 안되는거야?
그걸 알아가는게 코딩임
이건뭐 어떻게 찾아야될지도 모르겠다
자바 도큐 가면 라이브러리 함수에 대한 설명 다 나와있음
toList를 해버리면 List[ArrayList] 이게 나오고 collect를 하면 List[List[Integer]] 이게 나와요 걍 잘못된 메서드를 호출한거
김대기 속꽉찬 실수였노 ㅋㅋ
ArrayList도 List 변수에 넣을 수 있는거 아님..? 1차원 리스트는 되던데
List[List[Integer]] arr2 = Stream.generate(() -> new ArrayList()).limit(10).collect(Collectors.toList()); List[List[Integer]] arr3 = Stream.generate(() -> new ArrayList()).flatMap(list - list.stream()).limit(10).toList();
할거면 이렇게 해야징
와 오지네... 코드 분석해보고 공부좀해야겠다 존나 고마움
님이 원하는걸 하려면 이렇게 해야함 제네릭 공부좀 해야될듯 List[List[Integer]] arr2 = Stream.generate(() - new ArrayList()).limit(10).collect(Collectors.toList()); List[? extends List] arr3 = Stream.generate(() - new ArrayList()).limit(10).toList();
뭐지 ㅋㅋㅋ 내가보기엔 List[List]랑 List[? extends List]랑 똑같아 보이는데 아직 흐접이라 그런거겠지? ㅠㅠ 방향 잡아줘서 감사
어 근데 자세히 보니까 위쪽 코드도 문법 오류만 안난다 뿐이지 런타임 에러가 나는 코드임 애초에 new ArrayList()만 했는데 타입이 추론될수가 없어가지고;; 이렇게 하셈 List[List[Integer]] arr2 = Stream.generate(() -> new ArrayList()).limit(10).collect(Collectors.toList()); List[ArrayList[Integer]] arr3 = Stream.generate(() -> new ArrayList()).limit(10).toList();
오.. 김대기 빈수레 아니었구나
궁금한게 그부분인데 List[List] arr = List.of(new ArrayList(), new ArrayList()); 같은건 되는데 왜 Stream.toList() 쓰면 안되는거야?
미친놈인가 자바 문법 알려줬다고 빈수레 이지랄하네
좀 늦었는데 답변 글 다시 썼어요
https://gall.dcinside.com/board/view/?id=programming&no=2362385&page=1