Private Interfaces

后端 未结 2 1025
無奈伤痛
無奈伤痛 2021-01-05 16:31

How can we use the methods of a private interface in our code?

Abstract classes are something which cannot be instantiated. So, if we need to use methods of abstract

相关标签:
2条回答
  • 2021-01-05 16:46

    You extend in same way your private interface as in case of classes. you can implement that interface outsite of visibility scope.

    0 讨论(0)
  • 2021-01-05 17:04

    The private keyword means "anyone in the same class":

    public class Foo {
    
       private interface X {...}
       private class X1 implements X {...}
    }
    

    This means all classes declared inside of Foo can use the interface Foo.X.

    A common use case for this is the command pattern where Foo accepts, say, strings and converts them into internal command objects which all implement the same interface.

    If you add a second class Bar to the file Foo.java, then it can't see Foo.X.

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