Class ImmutableEntry<K,​V>

  • Type Parameters:
    K - the type of the key
    V - 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 of Map.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 an UnsupportedOperationException.

    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
     
    See Also:
    MapUtils.ofEntry(Object, Object), MapUtils.immutableEntry(Object, Object)
    • Constructor Detail

      • ImmutableEntry

        public ImmutableEntry​(K key,
                              V value)
    • Method Detail

      • setValue

        public V setValue​(V value)
        Specified by:
        setValue in interface java.util.Map.Entry<K,​V>
        Overrides:
        setValue in class DefaultEntry<K,​V>
      • 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 key
        V - the type of the value
        Parameters:
        key - the key
        value - the value
        Returns:
        an immutable entry with the specified key and value