Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why java provide facility to declare interface inside interface

Tags:

java

interface

I am trying different combination of inner classes.I wonder that java gives you facility to write interface inside interface.It does not give me any compile time error. Can anybody tell me what is the use of this ?

public interface IA {

    public interface IB{

    }
}
like image 490
MayurB Avatar asked Feb 15 '13 10:02

MayurB


1 Answers

This enables you to put the sub interface in a namespace that might make more sense than a different package. A good example of this from the Java API is the Map.Entry interface. An Entry only really makes sense in the context of something implements the Map interface, so it is defined as an interface inside an interface.

Note that other than with inner classes, inner interfaces are always static, as Jesse Glick mentions in his answer to a related question.

like image 90
akaIDIOT Avatar answered Sep 23 '22 19:09

akaIDIOT