learn java
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 The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "setting int to null" Watch "setting int to null" New topic

setting int to null

Martin Petransky

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.

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.)
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: setting int to null