Search code examples
javaif-statementequality-operator

Using the == operator twice in a if statement


Is it okay to do like this in java, does it work?

if (turtles.get(h).getX() == turtles.get(g).getX() == 450) { 
    //stuff here
}

Basically, i want to check if X is the same value as Y and that value should be 450.


Solution

  • No. It is the same as (turtles.get(h).getX() == turtles.get(g).getX()) == 450 - "incomparable types". if(turtles.get(h).getX() == 450 && turtles.get(g).getX() == 450).