• 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 Interfaces

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read the following discussion:
https://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".
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic