-
-
Save chandrasekhar4u/431839b9eac715c08b71 to your computer and use it in GitHub Desktop.
Enum Advantages in Java
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 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