1 /*
2 * Copyright (c) 2000, 2024, 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
23 * questions.
24 */
25
26 package java.util;
27
28 import java.io.ObjectInputStream;
29 import java.io.ObjectOutputStream;
30 import java.lang.reflect.Array;
31 import java.util.function.BiConsumer;
32 import java.util.function.BiFunction;
33 import java.util.function.Consumer;
34 import jdk.internal.access.SharedSecrets;
35
36 /**
37 * This class implements the {@code Map} interface with a hash table, using
38 * reference-equality in place of object-equality when comparing keys (and
39 * values). In other words, in an {@code IdentityHashMap}, two keys
40 * {@code k1} and {@code k2} are considered equal if and only if
41 * {@code (k1==k2)}. (In normal {@code Map} implementations (like
42 * {@code HashMap}) two keys {@code k1} and {@code k2} are considered equal
43 * if and only if {@code (k1==null ? k2==null : k1.equals(k2))}.)
44 *
45 * <p><b>This class is <i>not</i> a general-purpose {@code Map}
46 * implementation! While this class implements the {@code Map} interface, it
47 * intentionally violates {@code Map's} general contract, which mandates the
48 * use of the {@code equals} method when comparing objects. This class is
49 * designed for use only in the rare cases wherein reference-equality
50 * semantics are required.</b>
51 *
52 * <p>The view collections of this map also have reference-equality semantics
53 * for their elements. See the {@link keySet() keySet}, {@link values() values},
54 * and {@link entrySet() entrySet} methods for further information.
55 *
56 * <p>A typical use of this class is <i>topology-preserving object graph
57 * transformations</i>, such as serialization or deep-copying. To perform such
58 * a transformation, a program must maintain a "node table" that keeps track
59 * of all the object references that have already been processed. The node
|
1 /*
2 * Copyright (c) 2000, 2025, 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
23 * questions.
24 */
25
26 package java.util;
27
28 import java.io.ObjectInputStream;
29 import java.io.ObjectOutputStream;
30 import java.lang.reflect.Array;
31 import java.util.function.BiConsumer;
32 import java.util.function.BiFunction;
33 import java.util.function.Consumer;
34 import jdk.internal.access.SharedSecrets;
35
36 /**
37 * This class implements the {@code Map} interface with a hash table, using
38 * `==` in place of object-equality when comparing keys (and values).
39 * In other words, in an {@code IdentityHashMap}, two keys
40 * {@code k1} and {@code k2} are considered equal if and only if
41 * {@code (k1==k2)}. (In normal {@code Map} implementations (like
42 * {@code HashMap}) two keys {@code k1} and {@code k2} are considered equal
43 * if and only if {@code (k1==null ? k2==null : k1.equals(k2))}.)
44 *
45 * <p><b>This class is <i>not</i> a general-purpose {@code Map}
46 * implementation! While this class implements the {@code Map} interface, it
47 * intentionally violates {@code Map's} general contract, which mandates the
48 * use of the {@code equals} method when comparing objects. This class is
49 * designed for use only in the rare cases wherein reference-equality
50 * semantics are required.</b>
51 *
52 * <p>The view collections of this map also have reference-equality semantics
53 * for their elements. See the {@link keySet() keySet}, {@link values() values},
54 * and {@link entrySet() entrySet} methods for further information.
55 *
56 * <p>A typical use of this class is <i>topology-preserving object graph
57 * transformations</i>, such as serialization or deep-copying. To perform such
58 * a transformation, a program must maintain a "node table" that keeps track
59 * of all the object references that have already been processed. The node
|