I have gone through the following link Why would a static nested interface be used in Java?.
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 some other class in a different 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 a different file I have...
public abstract class XAppAgentBase extends IntentService
implements XClient, OnQueryResultSentListener {
}
There is no need to use static keyword for inner interface as interface declared inside an interface is by default static similar to saying variables defined in interfaces are be default public and static.
Is it a good design? - Depends on the design for which it is created for. Your code constrains accessibility of I2 interface to only those part of codes that have accessible to I1 Interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With