• 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 Interface and static ...

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I'm getting confused with all the implicit modifiers of the nested classes/interfaces
Hmm...got 2 questions for now...
1. Is the nested interface implicitly static (I know its implicitly public and abstract)? If yes, then what's the reason for this?
2. Is the class nested inside an enclosing interface implicitly static (I know its implicitly public)?
Thanks for any help in advance.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vidya Ram:
1. Is the nested interface implicitly static (I know its implicitly public and abstract)? If yes, then what's the reason for this?


From the JLS, §8.1.2 Inner Classes and Enclosing Instances:


Member interfaces (�8.5) are always implicitly static so they are never considered to be inner classes.


As far as "why" this is the case, let's argue the inverse. What good would it be to have a "non-static" nested interface? In which situtation would you want an interface to exist only when a class has been instantiated? In fact, all Interfaces, whether nested or not are implicity static. They always exist, whether a class that implements them has been instantiated or not.


2. Is the class nested inside an enclosing interface implicitly static (I know its implicitly public)?
Thanks for any help in advance.


Again, referring to the JLS, §9.5 Member Type Declarations:


Interfaces may contain member type declarations (�8.5). A member type declaration in an interface is implicitly static and public.


So, yup, it's static as well as public.
I hope that helps,
Corey
 
Vidya Ram
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Corey, its clear now.
But since all interfaces are implicitly static, then why declaring non-nested interface as static explicitly is not allowed?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vidya Ram:
Thanks Corey, its clear now.
But since all interfaces are implicitly static, then why declaring non-nested interface as static explicitly is not allowed?


I tried to find an answer for that when I originally answered your question, but couldn't find a clear answer. My guess is that it isn't much different than making an Interface abstract - you can do it, but it's rather redundant. If anyone knows of a reason, I'd be interested, as well.
Corey
 
reply
    Bookmark Topic Watch Topic
  • New Topic