inner class and enumerations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #1

    inner class and enumerations

    enumeration in java is nothing but a class concept.
    right??
    an inner class can be local to a method but why not enumerations?
    plz help.

    kind regards,
    Dmjpro.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by dmjpro
    enumeration in java is nothing but a class concept.
    right??
    an inner class can be local to a method but why not enumerations?
    plz help.

    kind regards,
    Dmjpro.
    You can define methods in enums and in those methods you can define local
    classes again. Or maybe I don't understand your question.

    kind regards,

    Jos

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by JosAH
      You can define methods in enums and in those methods you can define local
      classes again. Or maybe I don't understand your question.

      kind regards,

      Jos
      Ok let me be clear...

      look at this code ...

      [code=java]
      void test()
      {
      enum enum1{
      e1,e2;
      } //It is not possible .... why????
      }
      [/code]

      plz explain ...

      kind regards,
      dmjpro.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        The symbolic constants you define in your enum are implicitly defined as static
        final. Local classes can't have static members. Also see the JLS for a discussion
        about enums and this 'limitation'.

        kind regards,

        Jos

        Comment

        Working...