Search code examples
javajava-7jls

In Java source code, what does "Offloaded for" mean?


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?


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
    }