File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.)
I agree. Here's the link:
subject: setting int to null
It's not a secret anymore!