Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested Interfaces

 
Neil S Staish
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We often talk about nested classes. Does anyone have any tips/notes/commentary on nested interfaces (interfaces inside classes and interfaces)? :roll:
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the following discussion:
http://www.coderanch.com/t/236382/java-programmer-SCJP/certification/Inner-Interfaces-vs-Nested-Interfaces
You can also do a search in this forum with the keywords "nested interface".
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(1) Interfaces declared inside a class or other interface are always implicitly static.
So what? This fact is not particularly useful, except that inner classes may not declare static things (static initializers, static fields, static methods, static nested classes, or interfaces).
Inner classes may not declare interfaces. Top-level classes, static member classes and interfaces may declare interfaces.
(2) Interfaces declared in classes can have private, default, protected or public access. Interfaces declared in interfaces are implicitly public.
(3) Static nested types serve as a structuring and scoping mechanism for logically related types.
Sources: JLS 8.1.2, 8.5, 9.5, The Java Programming Language 5.1, 5.6
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Member interfaces are always implicitly public and static (these modifiers are allowed but are unnecessary), abstract (use is discouraged) and can be declared strictfp. Furthermore, interfaces which are class members can be declared protected or private.
Member interfaces, being implicitly static, cannot be declared in non-static nested classes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic