This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 688

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:
subject: setting int to null
Similar Threads
Values of Hash Map to be 2-dimensional array
array declaration
exception while running code
Problem in Arrays passing.