Skip to content

Instantly share code, notes, and snippets.

@gregoriokusowski
Last active September 25, 2015 02:26
Show Gist options
  • Save gregoriokusowski/8f1aa122a9f512f78f42 to your computer and use it in GitHub Desktop.
Save gregoriokusowski/8f1aa122a9f512f78f42 to your computer and use it in GitHub Desktop.
Abtract methods on java enums
public enum Operacao {
SOMA ("+") {
@Override
Integer executa(Integer a, Integer b) {
return a + b;
}
},
SUBTRACAO ("-") {
@Override
Integer executa(Integer a, Integer b) {
return a - b;
}
},
MULTIPLICACAO ("*"){
@Override
Integer executa(Integer a, Integer b) {
return a * b;
}
},
DIVISAO ("/") {
@Override
Integer executa(Integer a, Integer b) {
return a / b;
}
};
private final String sinal;
private Operacao(String sinal) {
this.sinal = sinal;
}
public String getSinal() {
return sinal;
}
abstract Integer executa(Integer a, Integer b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment