4320 * {@link Collections#unmodifiableList Collections.unmodifiableList}
4321 * or <a href="List.html#unmodifiable">Unmodifiable Lists</a>.
4322 *
4323 * @param <T> the class of the objects in the array
4324 * @param a the array by which the list will be backed
4325 * @return a list view of the specified array
4326 * @throws NullPointerException if the specified array is {@code null}
4327 */
4328 @SafeVarargs
4329 @SuppressWarnings("varargs")
4330 public static <T> List<T> asList(T... a) {
4331 return new ArrayList<>(a);
4332 }
4333
4334 /**
4335 * @serial include
4336 */
4337 private static class ArrayList<E> extends AbstractList<E>
4338 implements RandomAccess, java.io.Serializable
4339 {
4340 private static final long serialVersionUID = -2764017481108945198L;
4341 private final E[] a;
4342
4343 ArrayList(E[] array) {
4344 a = Objects.requireNonNull(array);
4345 }
4346
4347 @Override
4348 public int size() {
4349 return a.length;
4350 }
4351
4352 @Override
4353 public Object[] toArray() {
4354 return Arrays.copyOf(a, a.length, Object[].class);
4355 }
4356
4357 @Override
4358 @SuppressWarnings("unchecked")
4359 public <T> T[] toArray(T[] a) {
|
4320 * {@link Collections#unmodifiableList Collections.unmodifiableList}
4321 * or <a href="List.html#unmodifiable">Unmodifiable Lists</a>.
4322 *
4323 * @param <T> the class of the objects in the array
4324 * @param a the array by which the list will be backed
4325 * @return a list view of the specified array
4326 * @throws NullPointerException if the specified array is {@code null}
4327 */
4328 @SafeVarargs
4329 @SuppressWarnings("varargs")
4330 public static <T> List<T> asList(T... a) {
4331 return new ArrayList<>(a);
4332 }
4333
4334 /**
4335 * @serial include
4336 */
4337 private static class ArrayList<E> extends AbstractList<E>
4338 implements RandomAccess, java.io.Serializable
4339 {
4340 @java.io.Serial
4341 private static final long serialVersionUID = -2764017481108945198L;
4342 private final E[] a;
4343
4344 ArrayList(E[] array) {
4345 a = Objects.requireNonNull(array);
4346 }
4347
4348 @Override
4349 public int size() {
4350 return a.length;
4351 }
4352
4353 @Override
4354 public Object[] toArray() {
4355 return Arrays.copyOf(a, a.length, Object[].class);
4356 }
4357
4358 @Override
4359 @SuppressWarnings("unchecked")
4360 public <T> T[] toArray(T[] a) {
|