The expression is basically identical to the expression:
if ( (cat != null && cat.getColor() == "orange") || cat.getColor() == "grey") { ... }
The priority order here is that AND ( && ) has a higher priority than OR ( || ).
You should also know that using == to check for equality of strings will sometimes work in Java, but thatโs not how you should do it. You must do:
if (cat != null && ("orange".equals(cat.getColor()) || "grey".equals(cat.getColor()))) { ... }
those. use equals() methods to compare String , not == , which simply refer to equality. Link string equality can be misleading. For example:
String a = new String("hello"); String b = new String("hello"); System.out.println(a == b);
cletus Feb 15 2018-10-15T00 : 00Z
source share