Skip to content

Instantly share code, notes, and snippets.

@chandrasekhar4u
Created September 20, 2014 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chandrasekhar4u/431839b9eac715c08b71 to your computer and use it in GitHub Desktop.
Save chandrasekhar4u/431839b9eac715c08b71 to your computer and use it in GitHub Desktop.
Enum Advantages in Java
public enum Foo {
A("C") {
void doSomething() {
System.out.println("A: " + this.var);
}
},
B("D") {
void doSomething() {
System.out.println("B: " + this.var);
}
};
protected String var;
Foo(String var) {
this.var = var;
}
abstract void doSomething();
public static void main(String[] args) {
method(Foo.A);
method(Foo.B);
}
static void method(Foo foo) {
foo.doSomething();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment