Enum is basically a special class type, and can have methods and fields just like any other class. Any one know about the Enums Template Methods. Please give a real example for Template Methods on Enums. And can you explain about Enum Reverse Lookups.
Java 5.0 Enum tricks, specially have a look on the video.
Here is a simple example of a "command" enumeration:
public enum Toy {
DOLL() {
@Override public void execute() {
System.out.println("I'm a doll.");
}
},
SOLDIER() {
@Override public void execute() {
System.out.println("I'm a soldier.");
}
};
//template method
public abstract void execute();
}
Here objects Doll and Soldier both have a different implementation of the function execute().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With