Campbell Ritchie wrote:It isn't a convention about where you declare the enum tpe, but a design decision.
Mike Simmons wrote:So if the nested class is complex, move it out of the way.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:If a nested class is complex, it's likely it should be an independent class.
Antonio Moretti wrote:If it's nested it's a bit awkward to set an enum-type field with a constructor because you have to do [reference name].[enum name].[field name].
You would usually use ClassName.NestedEnumName.fieldName because nested enums are implicitly static.Antonio Moretti wrote:. . . you have to do [reference name].[enum name].[field name]. . . .
Campbell Ritchie wrote:You would usually use ClassName.NestedEnumName.fieldName because nested enums are implicitly static.
Antonio Moretti wrote:Aren't all enums static
or rather their fields?
Antonio Moretti wrote:Stephan, thanks. Very interesting but you lost me a bit there. What do you mean by a top level enum?
Also, why might we want an enum to have instance fields?
Stephan van Hulst wrote:
Antonio Moretti wrote:
Also, why might we want an enum to have instance fields?
For the same reason a class has instance fields. An enum constant is just an object like any other, except that you have a fixed number of them.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
More than enhanced; it is a completely new concept.Jesse Silverman wrote:. . . enum in C or C++ which is just a fixed set of values, usually seen as an int. . . .
The original version added, “which are simply glorified integers.” Maybe somebody complained because the bit about glorified integers was removed from the tutorial page quite quickly.Java programming language enum types are much more powerful than their counterparts in other languages. . . .
Campbell Ritchie wrote:
The Java™ Tutorials say,The original version added, “which are simply glorified integers.” Maybe somebody complained because the bit about glorified integers was removed from the tutorial page quite quickly.Java programming language enum types are much more powerful than their counterparts in other languages. . . .
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
It cuts both ways; I think when MS designed C#, they learnt from mistakes made with Java®.Jesse Silverman wrote:. . . something came quite late to Java, yet the Java team learned from the mistakes of others . . .
What are you doing in my house? Get 'em tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|