gnodet commented on code in PR #2363: URL: https://github.com/apache/maven/pull/2363#discussion_r2100473936
########## src/mdo/java/ImmutableCollections.java: ########## @@ -79,32 +65,7 @@ public int size() { }; static <E> List<E> copy(Collection<E> collection) { - if (collection == null) { - return emptyList(); - } else if (collection instanceof AbstractImmutableList) { - return (List<E>) collection; - } else { - switch (collection.size()) { - case 0: - return emptyList(); - case 1: - return singletonList(collection.iterator().next()); - case 2: - Iterator<E> it = collection.iterator(); - return new List2<>(it.next(), it.next()); - default: - return new ListN<>(collection); - } - } - } - - @SuppressWarnings("unchecked") - static <E> List<E> emptyList() { - return (List<E>) EMPTY_LIST; - } - - static <E> List<E> singletonList(E element) { - return new List1<>(element); + return collection == null ? List.of() : List.copyOf(collection); Review Comment: List.of() also returns an immutable list (although not the same objectas Collections.emptyList()). It's a more concise form, and I think the best practice will be to use List.of() and Map.of() instead of the similar methods from Collections. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org