What's the benefit of using enum embedded inside a class in JAVA?

Marian Paździoch

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
    }
}
Stephen C

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What's the benefit of using enum embedded inside a class in JAVA?

From Dev

What's the benefit of using a Result?

From Dev

What's the benefit of using a Result?

From Dev

What's the benefit using Gulp over Prepros?

From Dev

What's the benefit of exceptions specification in Java?

From Dev

What's the benefit of wildcard generics in Java?

From Dev

c++: enum inside of a class using "enum class"

From Dev

In Ruby, what is the benefit initializing a class instance using "def initialize ( value = '') "

From Dev

What is the benefit of using compose?

From Dev

What is the best way to store a reference to an arbitrary class inside an enum constant using the least memory on initialization as possible?

From Dev

Private enum location inside a class in Java

From Dev

(JAVA Enums) - Anonymous class inside enum constant

From Dev

clojure access enum defined inside a java class

From Java

What's the benefit of using reactive programming over ExecutorService?

From Dev

What's the benefit of using async to return data from database?

From Dev

What's the benefit of using bytes package over strings?

From Dev

What's the benefit of using numbers as properties in a javascript object initialization?

From Dev

What's the benefit of using reactive programming over ExecutorService?

From Dev

Is using a enum class inside of a class class un-necessary

From Dev

What is the benefit of using WebSphere MQ classes for Java rather than JMS?

From Dev

Using Spring injection inside a Java enum

From Dev

What's the benefit of MPI Datatype?

From Dev

What's the benefit of MPI Datatype?

From Dev

For the java class, what are the differences between using "new" inside the constructor and using "new" outside the class?

From Dev

What is the benefit of using RoutedCommands in WPF

From Dev

What is the benefit of using exponential backoff?

From Dev

what is the benefit of using a BroadcastReceiver in android?

From Dev

What is the real benefit of using UUIDs?

From Dev

What is the benefit of using a HyperlinkedModelSerializer in DRF?

Related Related

  1. 1

    What's the benefit of using enum embedded inside a class in JAVA?

  2. 2

    What's the benefit of using a Result?

  3. 3

    What's the benefit of using a Result?

  4. 4

    What's the benefit using Gulp over Prepros?

  5. 5

    What's the benefit of exceptions specification in Java?

  6. 6

    What's the benefit of wildcard generics in Java?

  7. 7

    c++: enum inside of a class using "enum class"

  8. 8

    In Ruby, what is the benefit initializing a class instance using "def initialize ( value = '') "

  9. 9

    What is the benefit of using compose?

  10. 10

    What is the best way to store a reference to an arbitrary class inside an enum constant using the least memory on initialization as possible?

  11. 11

    Private enum location inside a class in Java

  12. 12

    (JAVA Enums) - Anonymous class inside enum constant

  13. 13

    clojure access enum defined inside a java class

  14. 14

    What's the benefit of using reactive programming over ExecutorService?

  15. 15

    What's the benefit of using async to return data from database?

  16. 16

    What's the benefit of using bytes package over strings?

  17. 17

    What's the benefit of using numbers as properties in a javascript object initialization?

  18. 18

    What's the benefit of using reactive programming over ExecutorService?

  19. 19

    Is using a enum class inside of a class class un-necessary

  20. 20

    What is the benefit of using WebSphere MQ classes for Java rather than JMS?

  21. 21

    Using Spring injection inside a Java enum

  22. 22

    What's the benefit of MPI Datatype?

  23. 23

    What's the benefit of MPI Datatype?

  24. 24

    For the java class, what are the differences between using "new" inside the constructor and using "new" outside the class?

  25. 25

    What is the benefit of using RoutedCommands in WPF

  26. 26

    What is the benefit of using exponential backoff?

  27. 27

    what is the benefit of using a BroadcastReceiver in android?

  28. 28

    What is the real benefit of using UUIDs?

  29. 29

    What is the benefit of using a HyperlinkedModelSerializer in DRF?

HotTag

Archive