So um I was thinking about this code and I’m really wondering which is faster.
Random random = new Random();
int rand = random.nextInt(2);
if(rand == 0) {
// DO SOMETHING
}else if(rand == 1) {
// DO SOMETHING ELSE
}
Or this.
// Let's say this array is filled only when the program starts and is never changed.
Action[] actions = {
new Action() {
public void doAction() {
// DO SOMETHING
}
},
new Action() {
public void doAction() {
// DO SOMETHING ELSE
}
}};
// Now let's say we do this in a loop everytime we update the game or something
Random random = new Random();
int rand = random.nextInt(2);
acionts[rand].doAction();
interface Action {
public void doAction();
}