public static class AbstractMap.SimpleImmutableEntry
extends Object implements Entry<K, V>, Serializable
| java.lang.Object | |
| ↳ | java.util.AbstractMap.SimpleImmutableEntry<K, V> |
一个条目维护一个不可变的键和值。 该课程不支持方法setValue 。 在返回键值映射的线程安全快照的方法中,此类可能很方便。
Public constructors |
|
|---|---|
AbstractMap.SimpleImmutableEntry(K key, V value) 创建一个表示从指定键到指定值的映射的条目。 |
|
AbstractMap.SimpleImmutableEntry(Entry<? extends K, ? extends V> entry) 创建一个表示与指定条目相同映射的条目。 |
|
Public methods |
|
|---|---|
boolean |
equals(Object o) 将指定的对象与此条目进行比较以求相等。 |
K |
getKey() 返回与此条目对应的键。 |
V |
getValue() 返回与此条目相对应的值。 |
int |
hashCode() 返回此映射条目的哈希码值。 |
V |
setValue(V value) 用指定的值替换与此条目相对应的值(可选操作)。 |
String |
toString() 返回此映射条目的字符串表示形式。 |
Inherited methods |
|
|---|---|
java.lang.Object
|
|
java.util.Map.Entry
|
|
AbstractMap.SimpleImmutableEntry (K key,
V value)
创建一个表示从指定键到指定值的映射的条目。
| Parameters | |
|---|---|
key |
K: the key represented by this entry |
value |
V: the value represented by this entry |
AbstractMap.SimpleImmutableEntry (Entry<? extends K, ? extends V> entry)
创建一个表示与指定条目相同映射的条目。
| Parameters | |
|---|---|
entry |
Entry: the entry to copy |
boolean equals (Object o)
将指定的对象与此条目进行比较以求相等。 如果给定的对象也是映射条目并且两个条目表示相同的映射,则返回true 。 更正式地,如果两个条目e1和e2表示相同的映射
(e1.getKey()==null ?
e2.getKey()==null :
e1.getKey().equals(e2.getKey()))
&&
(e1.getValue()==null ?
e2.getValue()==null :
e1.getValue().equals(e2.getValue())) This ensures that the
equals method works properly across different implementations of the
Map.Entry interface.
| Parameters | |
|---|---|
o |
Object: object to be compared for equality with this map entry |
| Returns | |
|---|---|
boolean |
true if the specified object is equal to this map entry |
也可以看看:
V getValue ()
返回与此条目相对应的值。
| Returns | |
|---|---|
V |
the value corresponding to this entry |
int hashCode ()
返回此映射条目的哈希码值。 映射条目e的哈希码被定义为:
(e.getKey()==null ? 0 : e.getKey().hashCode()) ^ (e.getValue()==null ? 0 : e.getValue().hashCode())This ensures that
e1.equals(e2) implies that
e1.hashCode()==e2.hashCode() for any two Entries
e1 and
e2, as required by the general contract of
hashCode().
| Returns | |
|---|---|
int |
the hash code value for this map entry |
也可以看看:
V setValue (V value)
用指定的值替换与此条目相对应的值(可选操作)。 这个实现只是抛出UnsupportedOperationException ,因为这个类实现了一个不可变的映射条目。
| Parameters | |
|---|---|
value |
V: new value to be stored in this entry |
| Returns | |
|---|---|
V |
(Does not return) |
| Throws | |
|---|---|
UnsupportedOperationException |
always |
String toString ()
返回此映射条目的字符串表示形式。 此实现返回此条目的键的字符串表示形式,后跟等号字符(“ = ”),后跟此条目值的字符串表示形式。
| Returns | |
|---|---|
String |
a String representation of this map entry |