Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setting int to null  RSS feed

 
Martin Petransky
Greenhorn
Posts: 15
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!