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?
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.