Skip to content

Instantly share code, notes, and snippets.

@arahansa
Created August 2, 2016 10:43
Show Gist options
  • Save arahansa/def5403c2c07995aabf5c7c6efab4d8f to your computer and use it in GitHub Desktop.
Save arahansa/def5403c2c07995aabf5c7c6efab4d8f to your computer and use it in GitHub Desktop.
enum, 이늄
public enum Animal {
CAT {
public String makeNoise() { return "MEOW!"; }
},
DOG{
public String makeNoise() { return "WOOF!"; }
},
HORSE{
public String makeNoise() { return "NEIGH!"; }
};
public abstract String makeNoise();
}
public class HelloWorld {
public static void main(String[] args) {
System.out.print(Calc.PLUS.calc(3,4));
}
static enum Calc {
PLUS((Integer o1, Integer o2) -> o1 + o2),
MINUS((Integer o1, Integer o2) -> o1 - o2);
private final BiFunction<integer,integer,integer> op;
Calc(BiFunction<integer,integer,integer> op) {
this.op = op;
}
public int calc(int o1, int o2) {
return op.apply(o1,o2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment