There is a possiblity that this may be a dupicate question.
I initialize a String variable to null.I may or may not update it with a value.Now I want to check whether this variable is not equal to null and whatever I try I get a null pointer exception.I can’t afford to throw nullpointer exception as it is costly.Is there any workaround that is efficient.TIA
There is a possiblity that this may be a dupicate question. I initialize a
Share
If you use
you will not get a
NullPointerException.I suspect you’re doing:
which is throwing because
xis null, not becausex.yis null.If that doesn’t explain it, please post the code you’re using to test for nullity.