posted 10 years ago
If you declared i as an int then it would be initialised to 0, and so this would work fine. But you've declared it to be an Integer, which is a reference type and so it's initalised to null. Then on line 8 it is unboxed, but trying to unbox null will cause a NullPointerException.
I'm not sure why you're using new Test24(new Integer(4)) - simply new Test24(4) is clearer and has the same effect here.
And welcome to the Ranch!