Question on layer/peeling
vitalyd at gmail.com
Tue Jan 6 22:49:44 UTC 2015
I thought about getOrDefault as well, but the problem is that if you want
to get a value *and* find out if it was present in 1 operation, this won't
work. For cases where you don't care if the value was present or not and
proceeding with default is just as good as getting it from the map, no
problem, but that would be a limitation.
On Tue, Jan 6, 2015 at 5:45 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
> By the way, C# solves this by having TryGet type of methods that return a
>> boolean indicating success (I.e. found mapping) and set an out parameter
>> the value found. You'd need a lightweight tuple or multi return to do the
>> same in java, I think.
> Right, there's two ways to fix get():
> - Using the getOrDefault(key, sentinel) // added in Java 8
> - Using some sort of optional-like return type
> Not quite at that part of the road yet.
More information about the valhalla-dev