开发者

In java what is the benefit of extending from an interface

开发者 https://www.devze.com 2022-12-23 15:00 出处:网络
for example: SortedSet EXTENDS Set NavigableSet EXTENDS SortedSet is the benefit finally gained at the bottom most level (one that actually implements)?.

for example:

SortedSet EXTENDS Set
NavigableSet EXTENDS SortedSet

is the benefit finally gained at the bottom most level (one that actually implements)?. In above case it would be TreeSet

Would it be fair to say that if some class is EX开发者_StackOverflowTENDING an interface then that class SHOULD/MUST be an interface?


Yes, only interfaces can extend other interfaces. Classes implement interfaces, they don't extend them.

The purpose of an interface which extends another interface is to show that SortedSet is an extension of the Set interface. SortedSet is a Set, with additional operations.


is the benefit finally gained at the bottom most level (one that actually implements)?

The benefit is the same as for interfaces in general: specifying a contract. Interface hierarchies basically just save you some typing and prevent unintentional mismatches: SortedSet doesn't have to repeat the methods in Set, and there is no risk to end up with the same functionality in slightly different methods.

Would it be fair to say that if some class is EXTENDING an interface then that class SHOULD/MUST be an interface?

MUST would be correct. Classes cannot extend interfaces, only implement them.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号