>>What is get(Object) supposed to return when called on an object of type
>>HashMap<Object, Double> as in:
[quoted text clipped - 5 lines]
> Without actually trying it, I'm guessing that you'd get a null if you did a
> get() on a key that didn't exist.
The problem is that a double cannot be null. Think of the above line of code as
double x = hashMap.get(key).doubleValue();
This will throw a NPE as will the original code. The same happens for
Double d = null;
double x = d;
Cheers,
Simon
Thomas Hawtin - 09 May 2006 09:35 GMT
> The problem is that a double cannot be null. Think of the above line of code as
>
[quoted text clipped - 4 lines]
> Double d = null;
> double x = d;
The outrageous dangers of auto*un*boxing...
If you do want a "null" for double, don't use a very small number.
Double.NaN makes a suitable substitute. Note, to check for NaNs use
Double.isNan. IEEE 754 demands Double.NaN != Double.NaN...
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/