Results 1 to 4 of 4
  1. #1
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default public static enum vs enum class

    Hi,

    What is the main difference between using in a class a static enum or writting this enum in a separate class ?
    Both can be accesed from outside.
    thanks

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    You have direct access to the (private) static members of the outer class (when using a inner static enum)

  3. #3
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default

    Hi,

    That one i know, but the question is more, when do i use an enum class and when a static enum.
    what are the (dis)avantages of the one vs the other ?

    thanks

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Neatness mainly.
    And logical grouping.
    If the enum is small and associated purely with what is going on in the outer class then maybe keep it in there, but if it's for use outside the class, and/or has a load of its own code then I'd consider sticking it in its own file. Unless (as said above) you need access to some of the data in the outer class.

Similar Threads

  1. how to use this enum class
    By thorbcn in forum New To Java
    Replies: 1
    Last Post: 07-04-2011, 02:29 AM
  2. Class enum expected
    By Tyre in forum New To Java
    Replies: 10
    Last Post: 04-16-2011, 07:25 PM
  3. Setting values from One Enum type to another enum type.
    By reach2sudhakar in forum New To Java
    Replies: 3
    Last Post: 09-23-2010, 06:02 PM
  4. class, interface or enum expected?
    By Addez in forum New To Java
    Replies: 2
    Last Post: 08-26-2009, 07:54 PM
  5. Replies: 14
    Last Post: 05-28-2009, 05:44 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •