Create a gist now

Instantly share code, notes, and snippets.

@gitchandu /
Last active Oct 11, 2015

What would you like to do?
java :: enum as main
ENUM X => static final class X extends java.lang.Enum
ENUM X will have
instances seperated by commas (optional semi colon at the end)
[optional private modifier] Contructor with optional parameters
values() method which will return X[]
name(), toString() methods will return the name of specific enum
(ex: In the above example == SINGLETON.toString() == "SINGLETON")
instace and class variables/methods as usual in a class
ENUM X can only override toString() method
ENUM X can implement any interfaces
ENUM X can have main() method
ENUM X can have abstract method
ENUM X is serializable because java.lang.Enum implements interface
ENUM X have compareTo() method because java.lang.Enum implements interface
ENUM X's instances (constants) can be compared for equality using `==` or instance.equal() methods
// enum as Main
public enum Main {
private long timeStamp;
Main(long timeStamp) {
this.timeStamp = timeStamp;
public long getTimeStamp() {
return timeStamp;
public void run() {
public static void main(String[] tcs) {;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment