What's the benefit of using enum
embedded inside a class in JAVA? Like so:
public class Outter {
public enum Color {
WHITE, BLACK, RED, YELLOW, BLUE
}
}
The advantage of using an enum
is that it is the clearest and most type-safe way of expressing the programmer's intent. In this case ... it is declaring a set of 5 named "colour" values in a way that prevents them from being confused with any other values in your Java program.
The advantage of embedding the enum
cannot be discerned from this highly artificial example, but it is typically that the embedded class / enum has a close semantic relationship to the enclosing class.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments