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

Please explain why enums must not be declared within a method.

 
indra negi
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please help me in understanding this concept of not declaring an enum inside a method. This is just because, otherwise it will have a limited scope or there is some other reason.


Thanks in advance
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JLS

Nested enum types are implicitly static. It is permissable to explicitly declare a nested enum type to be static.

This implies that it is impossible to define a local enum, or to define an enum in an inner class
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can treat an enum like a class. Local classes can be declared only as final or abstract, while enum is static.
 
indra negi
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks a lot Ankit and Lukas.

I got the concept.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic