On Thu, 5 Nov 2020 17:26:48 GMT, Stuart Marks <sma...@openjdk.org> wrote:
>> src/java.base/share/classes/java/util/ImmutableCollections.java line 199: >> >>> 197: * safely reused as the List's internal storage, avoiding a >>> defensive copy. Declared >>> 198: * with Object... instead of E... as the parameter type so that >>> varargs calls don't >>> 199: * accidentally create an array of type other than Object[]. >> >> Why would that be a problem? If the resulting list is immutable, then the >> actual array type doesn't really matter, right? > > It's an implementation invariant that the internal array be Object[]. Having > it be something other than Object[] can lead to subtle bugs. See > [JDK-6260652](https://bugs.openjdk.java.net/browse/JDK-6260652) for example. you can still calls the varargs with an already created array listFromTrustedArray(new String[] { "foo" }); I think at least an assert is missing assert input.getClass() == Object.class; ------------- PR: https://git.openjdk.java.net/jdk/pull/1026