java - Lazy evaluation not working as it should -


i had evaluate boolean expression frecuently, converted in private method in it's class. here code it's causing me trouble:

//"x", "y" , "team" defined return (map.iswalkable(x,y) &&      (!map.isoccupied(x,y) || map.getoccupant(x, y).getteam() == team) ); 

methods should preety self-explanatory purpose of question. now, iswalkable , isoccupied both return boolean, , getoccupant method returning object reference. problem i'm getting nullpointerexception when executing piece of code, , shouldn't happening because isoccupied returns true if , if map.getoccupant != null (that's method returns). language supporting lazy boolean evaluation left right (as assume java is, or @ least that's able read) getoccupant method should never executed whenever return null right?

is more compiler-dependent thought was? should safer if used if statements, or there obvious i'm missing here, maybe operations resolved other way round.

the issue parenthesis. try

return (map.iswalkable(x,y) && (!map.isoccupied(x,y) || map.getoccupant(x, y).getteam() == team)); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -