aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes setting int to null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "setting int to null" Watch "setting int to null" New topic
Author

setting int to null

Martin Petransky
Greenhorn

Joined: Jul 30, 2010
Posts: 15

Hi there,

I just came across an interesting (at least for me) one that i would like to share.


This obviously won't compile:

But this will, as the null will be boxed to Integer, and you will get.. Of course, NumberFormatException at runtime.



OCPJP 6, OCEWCD 6
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Wow, that's amazing. It must be auto-boxing the result, but I would have sworn it wouldn't have compiled!

(I got a NullPointerException though.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting int to null