Question

In the java.util source code for HashMap, there are refactored out methods putForNullKey and getForNullKey with the comment:

/**
 * Offloaded version of put for null keys
 */
private V putForNullKey(V value) {

What does "offloaded" mean in this context? Refactored, or something more subtle?

Was it helpful?

Solution

This means nothing special. They just decided to have separate code for the put-logic if the key is null, and they separated that code from the non-null code into method putForNullKey.

When you look at put you will find the if-clause that checks for null-keys and - if so - delegates to putForNullKey:

public V put(K key, V value) {
    if (key == null)
        return putForNullKey(value);

    // ... here comes the put code for non-null-keys
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top