mkodekar / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Adding a new value to a map if absent however lazily #1867

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Need a putIfAbsent type method which takes a Builder rather than a created 
object as value along with Key K.
This in specific tries to create the object iff the key is absent.

Advantage: The value doesn't get un-necessarily created.

Original issue reported on code.google.com by venkates...@gmail.com on 20 Oct 2014 at 3:22

GoogleCodeExporter commented 9 years ago
Java 8 provides this as a new default method on Map, but I imagine this would 
be unnecessarily complicated before Java 8, if you had to write the anonymous 
Supplier instance -- it'd probably take more lines than just writing it the 
old-fashioned way.

Original comment by wasserman.louis on 20 Oct 2014 at 3:23

GoogleCodeExporter commented 9 years ago
Given that migrating to Java 8 takes significant amount of time ; i was hoping 
if it were to be implemented in guava

Original comment by venkates...@gmail.com on 20 Oct 2014 at 4:40

GoogleCodeExporter commented 9 years ago
As I was attempting to say, Guava could only really do this by letting you use 
an anonymous class, since you can't use lambdas until Java 8, and the anonymous 
class would be so verbose that your code would be shorter if you wrote it the 
"normal way."

Original comment by lowas...@google.com on 20 Oct 2014 at 4:41

GoogleCodeExporter commented 9 years ago
OK got it. thanks for clarification

Original comment by venkates...@gmail.com on 20 Oct 2014 at 4:42

GoogleCodeExporter commented 9 years ago
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:08

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:07