• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

nested interface

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am not sure if my question belongs to the advance forum but I am hoping to get some good advices here..
I have seen the following section in my code base .


Isn't this same as -

what is the advantage of using this kind of nested interface? Will C have the properties of A and B? What does C implements A.B mean exactly??
Kindly advise.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Isn't this same as ...


No; implementing an interface is not the same thing as extending a class.

What does C implements A.B mean exactly?


It means that C implements the A.B interface--there's no difference between implementing an interface and implementing a nested interface--they're both just interfaces.
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David!

Can you also answer these questions-

what is the advantage of using this kind of nested interface? Will C have the properties of A and B?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont know what is the advantage of this kind of interface.

Coming to your 2nd question : whether C has the properties of A and B ?

try below program

 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hari priya wrote:what is the advantage of using this kind of nested interface? Will C have the properties of A and B?


If interface B is only used in combination with interface A you could use a nested interface. This is an indication that interface B belongs somehow to interface A. Map.Entry is one such example.

C will have no combination with A anymore; interface B is implicitly static, and therefore the only real link between A and B is the namespace. A Map.Entry implementation does not need to know anything about the Map interface. For instance, java.util.AbstractMap.SimpleEntry is a static nested class has just one link to AbstractMap - and that's a static utility method that could just as well been omitted:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic