Closed GoogleCodeExporter closed 9 years ago
This:
V originalValue = map.get(key);
if (originalValue == null) {
Should be replaced with this:
if(!map.containsKey(key)){
After all, some Maps allow null values to be mapped.
Original comment by SeanPFl...@googlemail.com
on 12 Mar 2013 at 10:38
I disagree. For a null value allowing Maps used in a way allowing null values
it might be necessary. Otherwise it probably wastes time by using both
`contains` and `get`. So I'd suggest to use
V originalValue = map.get(key);
if (originalValue == null && !map.contains(key)) ...
instead (a benchmark needed?). An optimized implementation in Guava would be
nice.
Original comment by Maaarti...@gmail.com
on 13 Mar 2013 at 1:09
Agree with comment #2
Original comment by SeanPFl...@googlemail.com
on 14 Mar 2013 at 3:56
Obviously ConcurrentMap already has a putIfAbsent() method. Interestingly, in
JDK8 all Maps will have putIfAbsent() as well. (FWIW, the current default
implementation of putIfAbsent() for Map in JDK8 is just "return
containsKey(key) ? get(key) : put(key, value);")
Original comment by cgdec...@gmail.com
on 14 Mar 2013 at 6:33
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<issue id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:12
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:18
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
DannyLade
on 12 Mar 2013 at 10:26