Package io.microsphere.collection
Class ImmutableEntry<K,V>
- java.lang.Object
-
- io.microsphere.collection.DefaultEntry<K,V>
-
- io.microsphere.collection.ImmutableEntry<K,V>
-
- Type Parameters:
K
- the type of the keyV
- the type of the value
- All Implemented Interfaces:
java.util.Map.Entry<K,V>
public class ImmutableEntry<K,V> extends DefaultEntry<K,V>
An immutable implementation ofMap.Entry
that stores a fixed key-value pair.This class provides a read-only entry suitable for use in immutable maps. Once created, the key and value cannot be changed, and calling
setValue(Object)
will throw anUnsupportedOperationException
.Example Usage
ImmutableEntry<String, Integer> entry = ImmutableEntry.of("age", 30); System.out.println(entry.getKey()); // Output: age System.out.println(entry.getValue()); // Output: 30 // The following line would throw an exception: // entry.setValue(25); // throws UnsupportedOperationException
-
-
Constructor Summary
Constructors Constructor Description ImmutableEntry(K key, V value)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K,V>
ImmutableEntry<K,V>of(K key, V value)
Create an immutable entry with the specified key and value.V
setValue(V value)
-
-
-
Method Detail
-
of
public static <K,V> ImmutableEntry<K,V> of(K key, V value)
Create an immutable entry with the specified key and value.- Type Parameters:
K
- the type of the keyV
- the type of the value- Parameters:
key
- the keyvalue
- the value- Returns:
- an immutable entry with the specified key and value
-
-