jeudi 25 mars 2021

Java, turning if else into lambda expression [closed]

if((col+row)%2==0) {
    game.getTile(row, col).setValue(2);
}else {
    game.getTile(row, col).setValue(4);
    game2.getTile(row, col).setValue(2);
}

Would like to turn this into a lambda expression, sorta like this;

game.getTile(row, col).setValue((row,col) -> ((row+col)%2)== 0 ? 2 : 4);

Aucun commentaire:

Enregistrer un commentaire