Results 1 to 16 of 16
Like Tree1Likes
  • 1 Post By JosAH

Thread: creating enums without using enum class and private static final keywords

  1. #1
    johnmerlino is offline Member
    Join Date
    May 2014
    Posts
    54
    Rep Power
    0

    Default creating enums without using enum class and private static final keywords

    I am wondering if there is a way in jave to use enums WITHIN a class (without creating a separate enum class) without using private static final. Something like as folows:

    class My Class {

    myEnum {ACTIVE, INACTIVE, PENDING};

    }

    is there something like this available?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default Re: creating enums without using enum class and private static final keywords

    Why do you think you need this?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    johnmerlino is offline Member
    Join Date
    May 2014
    Posts
    54
    Rep Power
    0

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by KevinWorkman View Post
    Why do you think you need this?
    Why not? That's the way it is done in C.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: creating enums without using enum class and private static final keywords

    What have you tried? What error did you get? The posted code should almost work. It needs a small change.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,417
    Rep Power
    5

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by johnmerlino View Post
    Why not? That's the way it is done in C.
    First, what does that have to do with anything? Java is not C and C is not Java. Second, what's wrong with the enum construct offered by Java --> Enum Types (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,758
    Rep Power
    5

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by johnmerlino View Post
    Why not? That's the way it is done in C.
    I take it that you read somewhere that Java is a "C-based language". Its true, but take special note of the word -based-, its not C as already mentioned. Better learn the Java language instead of trying to program C in Java; that's already going to not work since the languages have a completely different design philosophy and are designed for completely different runtime environments.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by johnmerlino View Post
    Why not? That's the way it is done in C.
    This is so funny; C also has pointer arithmetic and manual memory management and function pointers and fuzzy definitions about sequence points and not type safe casts and a pre-processor and can run on top of the bare metal; should Java also have that? Fortran has computed gotos and common data blocks and equivalence relations; should Java also have that? Cobol has a verbosIty that even management should be able to understand; should Java also have that? Lisp has a lot of irritating single parentheses; should Java also have that? APL and Forth have a funny (incompatible) expression evaluation scheme; should Java also have that? Java has a lot of features those other languages don't have; if you want those other languages, you know where to find them ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,758
    Rep Power
    5

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by JosAH View Post
    This is so funny; C also has pointer arithmetic and manual memory management and function pointers and fuzzy definitions about sequence points and not type safe casts and a pre-processor and can run on top of the bare metal; should Java also have that? Fortran has computed gotos and common data blocks and equivalence relations; should Java also have that? Cobol has a verbosIty that even management should be able to understand; should Java also have that? Lisp has a lot of irritating single parentheses; should Java also have that? APL and Forth have a funny (incompatible) expression evaluation scheme; should Java also have that? Java has a lot of features those other languages don't have; if you want those other languages, you know where to find them ...

    kind regards,

    Jos
    lol, way to make a point... about two dozen times ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by gimbal2 View Post
    lol, way to make a point... about two dozen times ;)
    The OP doesn't understand that enums in Java are much more powerful than enums in C/C++; Java uses class object in disguise while C/C++ use simple ints for the purpose. Even after (de)serialization those Java enum values are strictly singletons (which I find rather amazing); who cares about the syntax?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    pbj
    pbj is offline Member
    Join Date
    Jun 2014
    Posts
    15
    Rep Power
    0

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by johnmerlino View Post
    Why not? That's the way it is done in C.
    If your looking for a java-like language, why not check out C#. It's like the twice removed, grand-daughter of C, and has its own enums.
    Last edited by pbj; 06-18-2014 at 04:50 PM.

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,758
    Rep Power
    5

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by pbj View Post
    If your looking for a java-like language, why not check out C#. It's like the twice removed, grand-daughter of C, and has its own enums. I'm a supporter of C#.
    Then I suggest you go advertise that on a C# forum, but this is a Java forum so you're reaching the wrong audience here. People who come to this forum want to use Java, they do not need to be told to use C#.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    pbj
    pbj is offline Member
    Join Date
    Jun 2014
    Posts
    15
    Rep Power
    0

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by gimbal2 View Post
    Then I suggest you go advertise that on a C# forum, but this is a Java forum so you're reaching the wrong audience here. People who come to this forum want to use Java, they do not need to be told to use C#.
    I was actually supporting Java by saying C# is a java-like language because... well it is. It is Microsoft's attempt at creating their own portable language. Sort of like how they tried to make Cobra... a direct ripoff of Python. Also the op may have not been aware that C has a descendant language that supports the use of enums while still being a member of the C family.
    Last edited by pbj; 06-18-2014 at 04:57 PM.

  13. #13
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,758
    Rep Power
    5

    Default Re: creating enums without using enum class and private static final keywords

    A nice and hostile assumption-based response (where does it say I'm a moderator?) to my otherwise neutral comment. Nice going. When you've gotten some fresh air yourself, I'll be waiting for your apology.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #14
    pbj
    pbj is offline Member
    Join Date
    Jun 2014
    Posts
    15
    Rep Power
    0

    Default Re: creating enums without using enum class and private static final keywords

    Quote Originally Posted by gimbal2 View Post
    A nice and hostile assumption-based response (where does it say I'm a moderator?) to my otherwise neutral comment. Nice going. When you've gotten some fresh air yourself, I'll be waiting for your apology.
    Don't see that happening.
    Last edited by pbj; 06-18-2014 at 05:02 PM. Reason: gimbal can go back on his high horse now

  15. #15
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,758
    Rep Power
    5

    Default Re: creating enums without using enum class and private static final keywords

    That's too bad.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  16. #16
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: creating enums without using enum class and private static final keywords

    @pbj: I found a notification that you reported (part of) this thread, it was supposed to be 'rude'; I found your replies (that you edited) just as rude. The original question has been answered, so I'm closing this thread.

    Jos
    Norm likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. private final class?
    By thelegendery in forum New To Java
    Replies: 4
    Last Post: 05-29-2013, 01:44 PM
  2. Retriving string from private static final class
    By KarlNorway in forum New To Java
    Replies: 9
    Last Post: 12-21-2011, 09:49 PM
  3. public static enum vs enum class
    By Dipke in forum New To Java
    Replies: 3
    Last Post: 08-30-2011, 10:45 AM
  4. final VS static keywords
    By hisheeraz in forum New To Java
    Replies: 7
    Last Post: 04-25-2011, 05:17 AM
  5. Replies: 2
    Last Post: 11-16-2010, 05:51 PM

Posting Permissions

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