Views of an excess interface set

xiaoxiao2021-03-06  52

If you see this code, what do you think?

Interface a {void method (); ...} Interface b extends a {// internal space}

Do you think it is very rubbish? Many interfaces in Java are empty, such as Cloneable, Serializable, RandomAccess, and more, they are called tag interfaces. However, the above example is more outrageous, since B and A are the same, do you want to inherit, isn't it? In fact, there is such example in Java, and set is one of them.

The SET interface declaration is as follows: public interface set extends collection For Collection: http://blog.9cbs.net/treeroot/archive/2004/09/09/99591.aspx

Compare the source code for Collection and SET you will find that the method in these two interfaces is actually the same, except for the notes different, that is, the set is not extension to the Collection, just for add, equals, hashcode definition instructions Different, because SET is not allowed to repeat the elements. This can be sure to say that this usage is not good (more interfaces), but the hierarchical interface is more obvious. It should be noted that although the SET and the method in the Collection are the same, they are totally different, and the list can be automatically converted to collection, but it is absolutely not converted to set, collect c = new arraylist () OK! Set s = New arraylist () WRONG !.

转载请注明原文地址:https://www.9cbs.com/read-115592.html

New Post(0)