Why do many Collection classes in Java extend the abstract class and implement the interface as well
2016-09-20 19:51
525 查看
Why do many Collection classes in Java extend the Abstract class and also implement the interface (which is also implemented by the given abstract class)?
For example,
class
also implements
implements
为什么 许多Collection 类 既继承了抽象类 也实现了 接口,如 HashSet extends AbstractSet implements Set,且 AbstractSet implements Set ?
It's a way to remember that this class really implements that interface.
It won't have any bad effect and it can help to understand the code without going through the complete hierarchy of the given class.
这种方式有助于记忆该类确实实现了该接口
这并没有什么坏处,这有助于我们理解代码 而不用去 check 它的完整的类层级关系。
For example,
class
HashSetextends
AbstractSetand
also implements
Set, but
AbstractSetalready
implements
Set.
为什么 许多Collection 类 既继承了抽象类 也实现了 接口,如 HashSet extends AbstractSet implements Set,且 AbstractSet implements Set ?
It's a way to remember that this class really implements that interface.
It won't have any bad effect and it can help to understand the code without going through the complete hierarchy of the given class.
这种方式有助于记忆该类确实实现了该接口
这并没有什么坏处,这有助于我们理解代码 而不用去 check 它的完整的类层级关系。
相关文章推荐
- What’s the difference between an interface and an abstract class in Java?
- difference between Abstract class and interface in java
- 【JavaLearning】接口与抽象类的比较(The comparison of Interface and Abstract Class )
- Java中的抽象类和接口 (Abstract Class and Interface in Java)
- Difference between Abstract Class and Interface in Java
- difference between Abstract class and interface in java
- difference between Interface and abstract class in Java
- Summary: Arrays vs. Collections && The differences between Collection Interface and Collections Class
- Programming in Java: Multi-threads and interface vs abstract class
- java abstract class and interface 讨论
- 设计: ListView 接口,and the missing read-only interfaces in java collection framework
- Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
- Java - Difference between Abstract class and Interface
- The Atomic classes in Java 5: AtomicInteger and AtomicLong,AtomicReference etc.
- Implement the quicksort algorithm in as many different ways as possible
- The Difference of Class.forName()、Class.forName().newInstance() and New in Java
- how to use a SQLite database in a standalone program with an HTML interface and VBScript as the programming language
- interface VS abstract class in java
- The Interface and Class Hierarchy Diagram of Java Collections
- The Default Methods And Static Methods In Java Interface