On Fri, 28 Oct 2022 19:51:21 GMT, Franz Wilhelmstötter <d...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/template/TemplateRuntime.java line 211: >> >>> 209: @SuppressWarnings("unchecked") >>> 210: public static <E> List<E> toList(E... elements) { >>> 211: return Collections.unmodifiableList(Arrays.asList(elements)); >> >> This is List.of(), please use List.of() instead > > `List.of()` can't be used here, since the elements are nullable, according to > the documentation. But the the returned list can still be modified, by > changing the given `elements` array. The input array must be explicitly > copied: > > public static <E> List<E> toList(E... elements) { > return Collections.unmodifiableList(new > ArrayList<>(Arrays.asList(elements))); > } Yes, it only occurs to me mid review, that said there is already an implementation in the jdk of a compact immutable that allow null inside the JDK (this implementation is used when stream.toList() is used). Using that implementation will avoid a bunch of indirection ------------- PR: https://git.openjdk.org/jdk/pull/10889