Arrays.asList()에 대한 호출을 보고합니다.
JDK 9 이상 버전에서 해당 호출을 Collections.singletonList(), Collections.emptyList() 또는 List.of()로 대체하여 메모리를 아낄 수 있습니다.
특히 인수가 없는 Collections.emptyList() 및 List.of()는 항상 공유 인스턴스를 반환합니다. 반면 인수가 없는 Arrays.asList()가 호출되면 항상 새 객체를 생성합니다.
참고: Collections.singletonList() 및 List.of()를 통해 반환된 목록은 불변이지만 Arrays.asList()가 반환된 목록은 set() 메서드 호출을 허용합니다.
이렇게 하면 드물지만 코드 손상이 발생할 수 있습니다.
예:
List<String> empty = Arrays.asList();
List<String> one = Arrays.asList("one");
빠른 수정을 적용한 후:
List<String> empty = Collections.emptyList();
List<String> one = Collections.singletonList("one");