I am trying to make a class that implements both Map<String,List<String>>
and List<String>
but am being blocked because there is one method that has an incompatible function signature:
from List<E>
boolean remove(Object o)
from Map<K,V>
V remove(Object o)
Strictly this function is optional according to the API, and as I intend my class to be immutable it is a function I don't want to support anyway (I would just return an UnsupportedOperationException). The problem is the signature is only keyed function name and parameter signature, not return type and I'm struggling to find a way to force the compiler on this. I expect the issue is the return memory region has different sizes for a primitive and an object so there is no way to mash the two together which is doubly sad when I don't even want the method! Not wanting to support the optional methods is what makes this different from the other questions I've seen regarding merged versions of the Collection classes with similar issues
I've heard rumours Java 1.8 has more options but I'm using Java 1.6 at the moment (the target platform is a bit of a legacy installation and migrating would be a moderate annoyance). Are there any ways to dodge around this?
background: The class is intended to be an encapsulation for parsed configuration files acting both as an iterable List (lines in order they were read in) and a Map which returns a filtered ordered List of values per configuration token. There are other ways to do this, but having the compatibility with Map and List would be significantly more elegant as this is planned to be a library function