• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Nested Interface?? in SCJP 1.4

 
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


How can we implement the nested interface? What it's use?
How can we extend an nested class that is declared inside an interface? what it's use?
I have implemented interface t1 in class NestedInterface,but not implement the methods of nested interface t2..how it compile and run?
[ December 05, 2006: Message edited by: Micheal John ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You asked for it:
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Micheal John posted December 05, 2006 05:57 AM

How can we implement the nested interface? What it's use?


use?


By the way, there is no need to override methodC

Bu.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is always possible to create bizzarre, convoluted code and then ask "what's it's use"? However it's not necessarily worthwhile to anyone. To see a realistic example of when a nested interface can be used, look at the Map interface, and the Map.Entry nested within it. The only purpose for this Entry interface is to be used as part of a Map, so the authors thought it made sense to present the interface as part of the Map interface. They certainly could have simply used a single separate Entry interface instead, but they chose not to. The idea is that when two classes or interfaces strongly related, we try to present them very close to each other (e.g. one nested in another).

The other way to look at this is, if they had said that you couldn't define an interface nested within a class or interface, there would probably be people writing strange code and asking "why not"? This is one of those language features that could have been omitted, as we never really need it - but there also doesn't seem to be a compelling reason to ban it, either. So you can always find people wanting to know "why" or "why not", and sometimes it really doesn't matter much either way. Maybe the engineers sometimes just tossed a coin to decide whether to allow some of these language features.
 
BWA HA HA HA HA HA HA! Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic