< prev index next >

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

Print this page




  51 
  52  * <P>Like most collection implementations {@code EnumMap} is not
  53  * synchronized. If multiple threads access an enum map concurrently, and at
  54  * least one of the threads modifies the map, it should be synchronized
  55  * externally.  This is typically accomplished by synchronizing on some
  56  * object that naturally encapsulates the enum map.  If no such object exists,
  57  * the map should be "wrapped" using the {@link Collections#synchronizedMap}
  58  * method.  This is best done at creation time, to prevent accidental
  59  * unsynchronized access:
  60  *
  61  * <pre>
  62  *     Map&lt;EnumKey, V&gt; m
  63  *         = Collections.synchronizedMap(new EnumMap&lt;EnumKey, V&gt;(...));
  64  * </pre>
  65  *
  66  * <p>Implementation note: All basic operations execute in constant time.
  67  * They are likely (though not guaranteed) to be faster than their
  68  * {@link HashMap} counterparts.
  69  *
  70  * <p>This class is a member of the
  71  * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
  72  * Java Collections Framework</a>.
  73  *
  74  * @author Josh Bloch
  75  * @see EnumSet
  76  * @since 1.5
  77  */
  78 public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
  79     implements java.io.Serializable, Cloneable
  80 {
  81     /**
  82      * The {@code Class} object for the enum type of all the keys of this map.
  83      *
  84      * @serial
  85      */
  86     private final Class<K> keyType;
  87 
  88     /**
  89      * All of the values comprising K.  (Cached for performance.)
  90      */
  91     private transient K[] keyUniverse;




  51 
  52  * <P>Like most collection implementations {@code EnumMap} is not
  53  * synchronized. If multiple threads access an enum map concurrently, and at
  54  * least one of the threads modifies the map, it should be synchronized
  55  * externally.  This is typically accomplished by synchronizing on some
  56  * object that naturally encapsulates the enum map.  If no such object exists,
  57  * the map should be "wrapped" using the {@link Collections#synchronizedMap}
  58  * method.  This is best done at creation time, to prevent accidental
  59  * unsynchronized access:
  60  *
  61  * <pre>
  62  *     Map&lt;EnumKey, V&gt; m
  63  *         = Collections.synchronizedMap(new EnumMap&lt;EnumKey, V&gt;(...));
  64  * </pre>
  65  *
  66  * <p>Implementation note: All basic operations execute in constant time.
  67  * They are likely (though not guaranteed) to be faster than their
  68  * {@link HashMap} counterparts.
  69  *
  70  * <p>This class is a member of the
  71  * <a href="{@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework">
  72  * Java Collections Framework</a>.
  73  *
  74  * @author Josh Bloch
  75  * @see EnumSet
  76  * @since 1.5
  77  */
  78 public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
  79     implements java.io.Serializable, Cloneable
  80 {
  81     /**
  82      * The {@code Class} object for the enum type of all the keys of this map.
  83      *
  84      * @serial
  85      */
  86     private final Class<K> keyType;
  87 
  88     /**
  89      * All of the values comprising K.  (Cached for performance.)
  90      */
  91     private transient K[] keyUniverse;


< prev index next >