< prev index next >

src/java.base/share/classes/java/util/List.java

Print this page
rev 14420 : 8133977: add specification for serialized forms
Reviewed-by: chegar, plevart, scolebourne
   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  90  * <h2><a name="immutable">Immutable List Static Factory Methods</a></h2>
  91  * <p>The {@link List#of(Object...) List.of()} static factory methods
  92  * provide a convenient way to create immutable lists. The {@code List}
  93  * instances created by these methods have the following characteristics:
  94  *
  95  * <ul>
  96  * <li>They are <em>structurally immutable</em>. Elements cannot be added, removed,
  97  * or replaced. Attempts to do so result in {@code UnsupportedOperationException}.
  98  * However, if the contained elements are themselves mutable,
  99  * this may cause the List's contents to appear to change.
 100  * <li>They disallow {@code null} elements. Attempts to create them with
 101  * {@code null} elements result in {@code NullPointerException}.
 102  * <li>They are serializable if all elements are serializable.
 103  * <li>The order of elements in the list is the same as the order of the
 104  * provided arguments, or of the elements in the provided array.
 105  * <li>They are <a href="../lang/doc-files/ValueBased.html">value-based</a>.
 106  * Callers should make no assumptions about the identity of the returned instances.
 107  * Factories are free to create new instances or reuse existing ones. Therefore,
 108  * identity-sensitive operations on these instances (reference equality ({@code ==}),
 109  * identity hash code, and synchronization) are unreliable and should be avoided.



 110  * </ul>
 111  *
 112  * <p>This interface is a member of the
 113  * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 114  * Java Collections Framework</a>.
 115  *
 116  * @param <E> the type of elements in this list
 117  *
 118  * @author  Josh Bloch
 119  * @author  Neal Gafter
 120  * @see Collection
 121  * @see Set
 122  * @see ArrayList
 123  * @see LinkedList
 124  * @see Vector
 125  * @see Arrays#asList(Object[])
 126  * @see Collections#nCopies(int, Object)
 127  * @see Collections#EMPTY_LIST
 128  * @see AbstractList
 129  * @see AbstractSequentialList


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  90  * <h2><a name="immutable">Immutable List Static Factory Methods</a></h2>
  91  * <p>The {@link List#of(Object...) List.of()} static factory methods
  92  * provide a convenient way to create immutable lists. The {@code List}
  93  * instances created by these methods have the following characteristics:
  94  *
  95  * <ul>
  96  * <li>They are <em>structurally immutable</em>. Elements cannot be added, removed,
  97  * or replaced. Attempts to do so result in {@code UnsupportedOperationException}.
  98  * However, if the contained elements are themselves mutable,
  99  * this may cause the List's contents to appear to change.
 100  * <li>They disallow {@code null} elements. Attempts to create them with
 101  * {@code null} elements result in {@code NullPointerException}.
 102  * <li>They are serializable if all elements are serializable.
 103  * <li>The order of elements in the list is the same as the order of the
 104  * provided arguments, or of the elements in the provided array.
 105  * <li>They are <a href="../lang/doc-files/ValueBased.html">value-based</a>.
 106  * Callers should make no assumptions about the identity of the returned instances.
 107  * Factories are free to create new instances or reuse existing ones. Therefore,
 108  * identity-sensitive operations on these instances (reference equality ({@code ==}),
 109  * identity hash code, and synchronization) are unreliable and should be avoided.
 110  * <li>They are serialized as specified on the
 111  * <a href="{@docRoot}/serialized-form.html#java.util.CollSer">Serialized Form</a>
 112  * page.
 113  * </ul>
 114  *
 115  * <p>This interface is a member of the
 116  * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 117  * Java Collections Framework</a>.
 118  *
 119  * @param <E> the type of elements in this list
 120  *
 121  * @author  Josh Bloch
 122  * @author  Neal Gafter
 123  * @see Collection
 124  * @see Set
 125  * @see ArrayList
 126  * @see LinkedList
 127  * @see Vector
 128  * @see Arrays#asList(Object[])
 129  * @see Collections#nCopies(int, Object)
 130  * @see Collections#EMPTY_LIST
 131  * @see AbstractList
 132  * @see AbstractSequentialList


< prev index next >