Was this an oversight? Or is it to do with the JVM?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Java does indeed have pointers–pointers on which you cannot perform pointer arithmetic.
From the venerable JLS:
And later:
(emphasis theirs)
So, to interpret, if you write:
then
myObjis a reference type which contains a reference value that is itself a pointer to the newly-createdObject.Thus if you set
myObjtonullyou are setting the reference value (aka pointer) tonull. Hence a NullPointerException is reasonably thrown when the variable is dereferenced.Don’t worry: this topic has been heartily debated before.