Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum

 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why is this illegal?
enum Test{ a,b,3}; i think enum are used to hold any values so that we can limit the values



this is possible even though K&B says that enum cannot be in a method....then why in a static class? and why not in a static method?
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because a static inner class is actually a top level nested class.

and an enum is a list of constant values assigned to a type.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isnt 3 a constant? what if i create a enum Test{1,2,3}?
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but 3 is different type then a&b.

i think enum{1,2,3} will do.
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
enum{1,2,3} doesnt compile...
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raju Champaklal wrote:enum{1,2,3} doesnt compile

How is enum {1,2,3} supposed to compile?? Is 1 or 2 or 3 a legal identifier??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic