migrator / guava-libraries-2

Guava: Google Core Libraries for Java 1.6+
0 stars 0 forks source link

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

Open migrator opened 9 years ago

migrator 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.

relevance: 1

migrator commented 9 years ago

summary: Not Defined

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.

status Not Defined creator: wasserman.louis created at: Oct 20, 2014

migrator commented 9 years ago

summary: Not Defined

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

status Not Defined creator: venkates...@gmail.com created at: Oct 20, 2014

migrator commented 9 years ago

summary: Not Defined

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."

status Not Defined creator: lowas...@google.com created at: Oct 20, 2014

migrator commented 9 years ago

summary: Not Defined

OK got it. thanks for clarification

status Not Defined creator: venkates...@gmail.com created at: Oct 20, 2014