java - Inspecting Integer variable within an if statement gives Null Pointer in Eclipse -
this question not related problem in particular. trying know what's going on.
i have following statement:
integer myint = null; if(myint!=null) { // it's not entering here... }
the execution flow normally, , lines within 'if' statement correctly not executed. when highlighting , inspecting (ctrl+shift+i) myint!=null instead of getting false got error within inspector stating:
myint.intvalue() null pointer exception
i wonder why eclipse need convertion int.
update
i have corrected sentence, stating inspector should return false. whole point of question why eclipse calling intvalue within inspector, , not discussion int or integer.
by inspecting integer object eclipse tries call the
intvalue()
function of integer class, return integer value of class, beacuse java want compare integer in same way compares int.
example:
int = 5; if (i == 6){ //will never enter here }
will give same result as
integer = new integer(5); if (i == 6) { //will never enter here }
beacuse java autounboxing you.
if integer null function intvalue() called convert integer number 5 camparison throws null pointer exception
Comments
Post a Comment