Similar problems:
Why do I need to implement the list interface when arraylist inherits abstractlist?
Why do map interfaces need to be implemented when hashmap inherits abstractmap?
Why do we need to implement the set interface when hashset inherits abstractset?
Today, we accidentally saw the source code of the vector. We found that the vector inherits the abstractlist (abstract class, implement list Interface) and the vector implements the list interface.CodeAs follows:
Public ClassVectorExtendsAbstractlistImplementsList, randomaccess, cloneable, java. Io. serializable
After thinking for a long time, I have never figured out why I want to do this? I have asked a few colleagues and I have no good explanation.
Therefore, for online search, the reason is that classs. getinterfaces () will return different results. For example, it is intended to be readable, or for future maintainability... However, these explanations are not so fascinating.
Finally, I found the answer on stackoverflow: it was a mistake. It was just a mistake made by the author of JDK. He thought it would be useful.
Details: <a href = "http://stackoverflow.com/questions/2165204/why-does-linkedhashsete-extend-hashsete-and-implement-sete"> http://stackoverflow.com/questions/2165204/why-does-linkedhashsete-extend-hashsete-and-implement-sete </a>
The first response was Kevin bourrillion, an employee from Google. He claimed to have asked Josh, the author of Java Collection, and obtained the above answer.
The answer to this question is indeed interesting.
Expansion problems:
Why does hashtable inherit the dictionary and implement the map interface? But does dictionary not implement the map interface?
The answer is that before Java 1.2, there was no map interface, only hashtable. Later, in, after introducing Java Collection, hashtable was rewritten to implement the map interface.
This is why the JDK source code contains inconsistent code styles, in a single sentence, for historical reasons. O (distinct _ distinct) O ~