Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

member declaration with in a interface

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every member type declaration(classes as well as interfaces)
appearing within the body of a directly enclosing interface is
implicitly static and public.

Any logical reason why they are implicitly static?
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Conversely, any logical reason why they wouldn't be?
Think about it some more
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot refer to "this" inside a interface. Hence there is no point in
going for a non-static member interface. But why the same for member class
inside an interface.
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To create the innner class you would need an instance of the containing class but there is no such thing: it's an interface. Ignoring that, what benefit would you derive with an inner class instance? Access to package and private scope fields and methods? There are none.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic