File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing values in enum

 
Jan Hoppmann
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

My problem is the following: I have a class with a (not static) enum in it that represents 6 values. If I now create an instance of this class, are the values in the enum independent from the values in other objects?
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I gather that your enum is defined as an inner class? If so, by definition per the JLS, inner Enum classes are implicitly static inner classes and so the enum's values are the same everywhere. In recognition of their being a static inner class, you need to access the enum from the outer class name and not an instance variable name:

Per the JLS, section 8.9:

Nested enum types are implicitly static. It is permissable to explicitly declare a nested enum type to be static.
 
Jan Hoppmann
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's exactly what I tried to do. Okay, so I'll change my implementation to a Map instead.
Enums are still new (and quite confusing) to me
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic