In LocalCache.java
@Override
public V put(K key, V value) {
checkNotNull(key);
checkNotNull(value);
int hash = hash(key);
return segmentFor(hash).put(key, hash, value, false);
}
is there a specific reason for adding a null check for the value as well. why can't cache have null values.
It's not the implementation; the implementation is required by the Cache
interface to do this (although that could be made clearer).
Null values would break at least the getAll, getIfPresent, and
getAllPresent methods. This would also imply that CacheLoader.load() should
be able to return null, but we discovered that many users assume that null
values get cached and many users assume they *don't *get cached, so that
was another minefield.
Use a Cache
clearer anyway!
On Tue, Apr 19, 2016 at 12:16 AM, Shrikant [email protected] wrote:
In LocalCache.java
@Override https://github.com/Override
public V put(K key, V value) {
checkNotNull(key);
checkNotNull(value);
int hash = hash(key);
return segmentFor(hash).put(key, hash, value, false);
}is there a specific reason for adding a null check for the value as well.
why can't cache have null values.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/google/guava/issues/2461
Kevin Bourrillion | Java Librarian | Google, Inc. | [email protected]
Most helpful comment
It's not the implementation; the implementation is required by the Cache
interface to do this (although that could be made clearer).
Null values would break at least the getAll, getIfPresent, and
getAllPresent methods. This would also imply that CacheLoader.load() should
be able to return null, but we discovered that many users assume that null
values get cached and many users assume they *don't *get cached, so that
was another minefield.
Use a Cache> and it will make your code
clearer anyway!
On Tue, Apr 19, 2016 at 12:16 AM, Shrikant [email protected] wrote:
Kevin Bourrillion | Java Librarian | Google, Inc. | [email protected]