This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

enum in method declaration  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Why enum cannot be declared with in a method ?
 
Author and ninkuma
Marshal
Posts: 66810
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enums are in the same category as classes. You can't declare classes in methods either, can you?
 
author
Sheriff
Posts: 23590
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be more exact, for classes, you are not allowed to declare static members for local classes. For enums, the members of the enum are static, so it is not possible to define a usable enum type at a method level.... hence, it is just not allowed.

Henry
 
Raja Narasimha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. As per the following program we declare a class in a method. Please let me know if you are referring this or something else.

Bear Bibeault wrote:Enums are in the same category as classes. You can't declare classes in methods either, can you?

 
Raja Narasimha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I got your point.

Henry Wong wrote:To be more exact, for classes, you are not allowed to declare static members for local classes. For enums, the members of the enum are static, so it is not possible to define a usable enum type at a method level.... hence, it is just not allowed.

Henry

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66810
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Henry's better explanation.
 
Henry Wong
author
Sheriff
Posts: 23590
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Raja Narasimha wrote:Thank you. I got your point.

Henry Wong wrote:To be more exact, for classes, you are not allowed to declare static members for local classes. For enums, the members of the enum are static, so it is not possible to define a usable enum type at a method level.... hence, it is just not allowed.



Of course, this is speculation. The correct answer is... it is not allowed because the JLS says that it is not allowed.

Henry
 
Henry Wong
author
Sheriff
Posts: 23590
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raja Narasimha,

Your post was moved to a new topic.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!