@FunctionalInterface public interface Object2ObjectFunction<K,V> extends Function<K,V>
Function; provides some additional methods that use polymorphism to avoid (un)boxing.
Type-specific versions of get(), put() and
remove() cannot rely on null to denote absence of
a key. Rather, they return a default
return value, which is set to 0/false at creation, but can be changed using
the defaultReturnValue() method.
For uniformity reasons, even functions returning objects implement the default
return value (of course, in this case the default return value is
initialized to null).
The default implementation of optional operations just throw an UnsupportedOperationException, except for the type-specific containsKey(), which return true. Generic versions of accessors delegate to
the corresponding type-specific counterparts following the interface rules.
Warning: to fall in line as much as possible with the
standard map interface, it is required that
standard versions of get(), put() and
remove() for maps with primitive-type keys or values return
null to denote missing keys rather than wrap the default
return value in an object. In case both keys and values are reference
types, the default return value must be returned instead, thus violating
the standard map interface when the default
return value is not null.
Function| Modifier and Type | Method and Description |
|---|---|
default V |
defaultReturnValue()
Gets the default return value.
|
default void |
defaultReturnValue(V rv)
Sets the default return value (optional operation).
|
V |
get(Object key)
Returns the value to which the given key is mapped.
|
default V |
put(K key,
V value)
Adds a pair to the map (optional operation).
|
default V |
remove(Object key)
Removes the mapping with the given key (optional operation).
|
apply, clear, containsKey, sizedefault V put(K key, V value)
key - the key.value - the value.Function.put(Object,Object)V get(Object key)
key - the key.Function.get(Object)default V remove(Object key)
key - the key.Function.remove(Object)default void defaultReturnValue(V rv)
get(), put() and remove() to
denote that the map does not contain the specified key. It must be
0/false/null by default.rv - the new default return value.defaultReturnValue()default V defaultReturnValue()
This default implementation just return the default null value
of the type (null for objects, 0 for scalars, false for Booleans).
Copyright © 2020. All rights reserved.