Since vector inherits abstractlist, why do we need to implement the list interface?

Source: Internet
Author: User

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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.