0

please I need help with a theoretical issue in Java SE. Below I detail the information I'm looking for:

Difference between internal interfaces (that is, nested, interfaces within others) and subinterfaces (that is, interfaces that extend from other interfaces, or interfaces that implement other interfaces, is this possible?), and most important, under what circumstances do we use each one? I mean, what do we use them for?

I know that there're internal interfaces, since in the Java API there is, for example, the Entry interface, of the java.util package, which is declared within the Map interface of the same package, Entry is an internal interface of Map. But I don't understand the functionality of these internal interfaces. I'd also like to know what the subinterfaces are for, so that I can distinguish them from the internal interfaces.

Greetings, F

FuRRRaira
  • 3
  • 1

1 Answers1

0

Nested interfaces are exactly the same as non-nested interfaces.

The only difference is that they're defined inside a class or interface instead of being defined outside, and that their name thus includes the enclosing class or interface name: Map.Entry instead of Entry.

That makes it clear that they are conceptually linked to their enclosing class or interface (i.e. Map.Entry makes it clear that it's an entry of a Map).

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thanks JB Nizet, I haven't any tutor so I really appreciate your help. I'm sorry I don't understand. I see that Map is an interface, not a class, so I'd like to know what is the purpose of introducing an interface into another in Java – FuRRRaira Nov 20 '19 at 18:20
  • It doesn't matter whether they're defined in a class or an interface. The explanation is the same. – JB Nizet Nov 20 '19 at 18:25
  • Oh Okay! Only the class or interface that encloses it can make use of that nested interface? Or what does it mean that they are conceptually linked to the class or interface that encloses it? – FuRRRaira Nov 20 '19 at 18:57
  • No. Read my answer: Nested interfaces are exactly the same as non-nested interfaces. It means it clear that the interface Entry has something to do with the type Map: it's the entry of a Map. – JB Nizet Nov 20 '19 at 19:29
  • Ah! That is, the internal interfaces are not functionally linked with the class or interface that encloses them (that is, the behavior of the internal interface doesn't affect to the behavior of the class or interface that encloses it, and vice versa). Then I understand what you said about "conceptually linked". Hahah incredible, thanks a lot! :) – FuRRRaira Nov 20 '19 at 21:18