What is the use of nested interfaces in this code

I used the following link. Why was the Java static nested interface used? .

In my code base, I have:

public interface I1{ public static interface I2 { public void doSomething(); } //some other methods public void myMethod(I2 myObject); } 

And in another class in another package:

 public abstract class SomeClass implements I2{ //mandatory method... } 

Now, my question is: "Is it really a good design to put I2 in I1 "?

EDIT:

 public interface XClientSession { static public interface OnQueryResultSentListener { public void onQueryResultSent(XQueryResult result); } public void setOnQueryResultSentListener(OnQueryResultSentListener listener); } 

/ And in another file I have ...

  public abstract class XAppAgentBase extends IntentService implements XClient, OnQueryResultSentListener { } 
+7
java
source share
2 answers

There is no need to use a static keyword for the internal interface, since the interface declared inside the interface is static by default, similar to the variables mentioned in the interfaces, is public and static by default.

Is this a good design? - Depends on the design for which it was created. Your code limits the availability of the I2 interface only to that part of the codes that is available for the I1 interface.

+1
source share

In java, it is absolutely correct to define an interface inside another

This is a coding style that says the I2 interface exists in I1 (or they are connected to each other)

0
source share

All Articles