• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Nested enum in enum.

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,

I've found a question like this:



And the question is what kind of import should be inserted in package pack2 so that it compiles. One of the answer is to use a static import like this:

And as it is written in the book: "You can do a static import on static object references, constants and static methods."
And thus why this import is legal? enum is none of the above cases.

Cheers,
Jan.
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nested enums are static members of the enclosing class. So, we need a static import there!
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Osykowski wrote:And as it is written in the book: "You can do a static import on static object references, constants and static methods."


The book was wrong here. Or rather, incomplete. Static nested types should have been included on the list. Or just refer to them all as static members, as AK just did.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when we declare enum inside a class it is implicitly static and final..
the best and the convinient way to do the import of enum is static import.

This static import statement uses the wildcard to say,
"I want to do static imports of ALL the static members in this class."


and here enum is a static member of a class
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shanky Sohar wrote:when we declare enum inside a class it is implicitly static and final..



Shanky, just for correction, enum objects are only static and final, but, here it's just a static member of the enclosing class. And, Mike is correct.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
correct, only objects are static and final,and enum is a static member of a class........
 
reply
    Bookmark Topic Watch Topic
  • New Topic