I would like to have an object that implements Map and List interfaces in Java. The idea is similar to a problem in this question: Java Ordered Map
I want to add name / value pairs to the list and keep the list in sequence, but also be able to search by name:
foo.put("name0", "value0");
foo.put("name1", "value1");
foo.get(1); --> Map.Entry("name1", "value1")
foo.get("name0"); --> "value0"
Here's the problem: when I create this class:
class Foo implements Map, List {
}
I get a compilation error:
"The return type is incompatible with Map.remove(Object)"
public boolean remove(Object o) {
return false;
}
If I do not implement the Map and List interfaces, then there are many Java collection methods that are not available for use in this data structure.
(In addition, the reason the solution proposed in the Java Ordered Map above does not work is because LinkedHashMap does not have a get (int) method. It is not possible to select records by index.)