Thursday, 8 August 2013

java Ternary operator some questions

java Ternary operator some questions

hiCI encountered a problem in worksCthe question like this:

Integer test1=null;
Integer test2=null;
i call them like this:

test2=(test1==null?test1:(test1+1));
test2=(test1==null?test1:-1);
then the java throw a NullPointerException,so iwrite another code like this:
test2=(test1==null?test1:test1);
this code is ok.
but,why? who can tell me,thanks.

No comments:

Post a Comment