Yep, that did the trick.

Double zero = 0d;
Double test = null;
Double test2 = true?test:zero;

Works.  Thanks Mike!  You've saved me a lot of if-else-ing just now :-)

Ramsey

On Oct 19, 2009, at 11:37 AM, Mike Schrag wrote:

The two values on either side of the colon have to be of the same type, so I suspect it's boxing the first one from Double down to double (and NPEing) then boxing back up to Double at the end? I put this in the "just don't do that" category. I personally don't like boxing -- I think it's very misleading and leads to weird bugs like this.

On Oct 19, 2009, at 11:31 AM, Ramsey Gurley wrote:

Hi all,

I've just discovered that while

Double test = true?null:0d; //result: test is null

works without error, the following

Double test2 = true?(new Object(){public Double testMethod(){return null;}}.testMethod()):0d; //<-Throws NPE

Throws a NullPointerException. :-/ Ok, that sucks, so what about this?

Double test3 = new Object(){public Double testMethod2(){return null;}}.testMethod2(); // result: test3 is null
Double test4 = true?test3:0d; //<-Throws NPE

Also throws a NullPointerException. I suspect this has something to do with the autoboxing, because

Object test5 = true?new Object(){public Object testMethod3(){return null;}}.testMethod3():0d;

Works fine. I'm running OS X 10.5 and java 1.5 here at work. Is this a known issue? Or is this somehow expected behavior?

Ramsey


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40mdimension.com

This email sent to [email protected]




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to