Created
August 2, 2016 10:43
-
-
Save arahansa/def5403c2c07995aabf5c7c6efab4d8f to your computer and use it in GitHub Desktop.
enum, 이늄
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 Animal { | |
CAT { | |
public String makeNoise() { return "MEOW!"; } | |
}, | |
DOG{ | |
public String makeNoise() { return "WOOF!"; } | |
}, | |
HORSE{ | |
public String makeNoise() { return "NEIGH!"; } | |
}; | |
public abstract String makeNoise(); | |
} |
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 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