java - Simplify boolean expression -


this question has answer here:

i have bit of code , eclipse telling me boolean expressions can simplified.

    knightturn == true && occupied ==true 

and

    knightturn == true 

both boolean knightturn , boolean occupied set false earlier in code.

    boolean knightturn=false      boolean occupied=false      @tags({"passed"}) public void passed ()  {     final int x = 50;     if (knightturn == true && occupied == true) {         (int i=0; i<x; i++) {             standknight.moveavatar(i, 0);             avatareditor.refresh();             i++;         }         occupied = false;     }  }  @tags({"failed"}) public void failed () {     final int x = 35;     if (knightturn == true) {         (int i=0; i<x; i++) {             standknight.moveavatar(i, i/2);             avatareditor.refresh();             i++;         }         occupied =  false;     } 

the code still runs should, how tidy bit , make simpler?

 if (knightturn == true && occupied == true) 

can written as

 if (knightturn && occupied) 

this reduces possibility of making mistakes these

if (knightturn = true) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -