Can You Write an Interface that Can Not be implemented?

前端 未结 3 1367
后悔当初
后悔当初 2021-01-13 21:32

This is related to final interface in java. Among the discussion there was that the concept of final in relation to interfaces is ambiguous. Would a final interface mean t

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-13 22:03

    Technically, you can, by specifying parameters that are not accessible to implementors - for example in the same package as the interface, with package-private visibility.

    But that does not make any sense. This interface is completely useless in this case.

    Update: One use comes into my mind, but this should not be done. If you want to use interfaces for constant definitions, in order to spare the bunch of modifier that an interface assumes, but you don't want to use the anti-pattern of implementing a constants-only interface.

提交回复
热议问题