Can I prevent an interface from being implemented?

后端 未结 1 913
伪装坚强ぢ
伪装坚强ぢ 2021-01-24 23:47

I have the following Situation:

public interface A {
    void doSomethingCool();
}

public interface B extends A {
    void doSomethingVeryBCool();
}
public inte         


        
相关标签:
1条回答
  • 2021-01-25 00:46

    You cannot directly enforce the interface not being implemented, however you can make the interface package-local:

    interface A {...} //no public
    

    This way classes outside that package cannot see the interface.

    EDIT: however, this does mean that you cannot do something like

    A a = getA();
    

    outside the package because A cannot be resolved.

    0 讨论(0)
提交回复
热议问题