Implement both Map and List interface in Java?

前端 未结 6 1778
死守一世寂寞
死守一世寂寞 2020-12-19 09:51

I\'d like to have an object that implements both the Map and the List interfaces in Java. The idea is similar to the problem in this question: Java Ordered Map

I wan

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 10:12

    It should be pointed out that the reason for the error is that Map contains the definition for the following remove method:

    V remove(Object key)
    

    While List defines:

    boolean remove(Object o) 
    

    And, in Java, methods cannot be overloaded based on their return type, so they are conflicting signatures, and cannot be implemented in the same class.

提交回复
热议问题