Last active
September 25, 2015 02:26
-
-
Save gregoriokusowski/8f1aa122a9f512f78f42 to your computer and use it in GitHub Desktop.
Abtract methods on java enums
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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