• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface Query

 
Ankur Mahajan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to declare one interface within another?
If yes then why and if no then why not.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12084
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you tried it? What happened?
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Look in the Java Language Specification. Look at first at Section 6.4.4
 
Ankur Mahajan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I have tried it and it is allowing to declare one interface within another but when I implement that interface in a class, it does not give error for "unimplemented methods" of inner interface.

but at first place why it is allowing to declare an interface inside another.
 
Ankur Mahajan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Campbell

According to specifications it can be done.
But can you tell,where it can be useful or when such declaration is needed.
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out java.util.Map and java.util.Map.Entry.

Map.Entry is an interface that only makes sense in the context of a Map. Declaring it as an inner interface creates a form of coupling between the two interfaces.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic