Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

java :: enum as main

View X.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
public enum Main {
SINGLETON(System.currentTimeMillis());
private long timeStamp;
Main(long timeStamp) {
this.timeStamp = timeStamp;
}
public long getTimeStamp() {
return timeStamp;
}
public void run() {
System.out.println(getTimeStamp());
}
 
public static void main(String[] tcs) {
SINGLETON.run();
}
}
View X.java
1 2 3 4 5 6 7 8 9 10
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.name() == SINGLETON.toString() == "SINGLETON")
instace and class variables/methods as usual in a class
ENUM X can implement any interfaces
ENUM X can have main() method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.