Skip to content

Instantly share code, notes, and snippets.

View BoBoMEe's full-sized avatar

Bo_Wang BoBoMEe

  • Beijing
View GitHub Profile
@BoBoMEe
BoBoMEe / Operation1.java
Last active January 1, 2017 10:01
Emum type with constant-specific method implementations
//Emum type with constant-specific method implementations
public enum Operation1 {
PLUS {
@Override double apply(double x, double y) {
return x + y;
}
},
MINUS {
@Override double apply(double x, double y) {
@BoBoMEe
BoBoMEe / Operation.java
Last active January 1, 2017 10:01
enum operations for plus,minus,times,divids(effective java)
//Emum type that switchs on its own value -- questionable
public enum Operation {
PLUS, MINUS, TIMES, DIVIDS;
//Do the arithmetic op represented by this constant
double apply(double x, double y) {
switch (this) {
case PLUS:
return x + y;
case MINUS: