• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why static classes are allowed in interfaces? What is the use of such a syntax?  RSS feed

 
Samar Bir
Greenhorn
Posts: 23
IntelliJ IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.

I am reading about interface and i see that classes are allowed inside interfaces which are implicitly static. Here is sample of code i created
and i am able to access the static method and fields as well. Here is the code snippet.



My question is what is the use of such static classes inside interface? If i don't have access to Foo, i can't ever invoke NestedClass.
Whats the design usage?

Thanks,
Samar
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can define classes inside classes, and you can also define classes inside interfaces. There's no reason why that should not be possible. However, it is not very common to define a class inside an interface, I can't remember ever doing or needing that in many years of Java programming. So, it is possible, but I don't think it's a very useful feature of Java.

Samar Bir wrote:If i don't have access to Foo, i can't ever invoke NestedClass.

What do you mean exactly with "if I don't have access to Foo"? What is "Foo"?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!