valhalla-dev Digest, Vol 6, Issue 3

Peter Levart peter.levart at gmail.com
Mon Dec 22 01:08:09 UTC 2014


On 12/21/2014 05:47 PM, Brian Goetz wrote:
>> 4) Map<int>.get() and "sentinel values"
>> --------------------------------------------------------
>> - null is a moderately good "sentinel value" for objects, but zero is 
>> not
>> so good for numbers;
>> - similar to the 'T.empty' syntax proposed above,  I propose a 
>> 'T.sentinel'
>> syntax for "no element".
>> eg, int.sentinel references -1, Object.sentinel references null.
>
> The reason int can't be null is that we have no natural and efficient 
> hardware representation for it; all 2^32 values in an 32-bit integer 
> are used for integers.  So changing the syntax from "null" to 
> "sentinel" doesn't help -- the real problem is, how do we represent 
> it?  Ballooning all integers to 64 bits just to accommodate a special 
> value is not going to fly.  And stealing "-1" as the "not to be used 
> as an int" value similarly doesn't fly; -1 is also an important integer.
>
> Applications and APIs are free to cut corners like "let's let -1 mean 
> 'no value'", but languages and VMs are not free to do this. 

Hi,

What happened to Optional?

If Optional could be morphed into a value type AND be specialized at the 
same time, then returning Optional<int> from Map<K, int>.getOptionaly(k) 
would be the right thing to do.

Peter.




More information about the valhalla-dev mailing list