Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there something called 'inner interface'?  RSS feed

 
Aakash Goel
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inner classes exist. Why not inner interfaces?
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to create an interface within interface or class??
 
Aakash Goel
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:Did you try to create an interface within interface or class??


yeah, they do get created.

also, Set is an interface and so is Collection.

But nowhere in K&B is a mention of innner interfaces.

So, I thought probably they are not inner interfaces after all.
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are inner interfaces but maybe nothing is asked about them in SCJP that's why nothing about them is given in K&B ...
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aakash Goel wrote:


So, I thought probably they are not inner interfaces after all.


They are not. Set is an interface that extends from Collection interface and its just a sub-interface... Its not an interface within another interface. From the specs here I see that Sun calls an interface within another interface as a "nested interface" I guess this nesting of an interface in another has only to do with some namespace resolution...
 
Paul Clapham
Sheriff
Posts: 22502
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishwanath brings up an important point. There is a rather complicated difference between a "nested class" and an "inner class"... I'm not going to try to explain it because I don't remember it correctly, but you might want to review that. Then it's quite likely that "inner interface" and "nested interface" would be the same concepts.
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



you can find questions related to inner ineterfaces too in Dan Chilosam's book.

avi sinha
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference between "inner" and "nested" is that only non-static nested class is called "inner class" (static nested class is not an inner class).

Nested interfaces are always implicitly static so inner interfaces does not exist.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!