Lasty, I tried to implements an hybrid structure in Java, something that looks like:
public class MapOfSet<K, V extends HasKey<K>> implements Set<V>, Map<K, Set<V>>
Where HasKey is the following interface:
public interface HasKey<K> { public K getKey(); }
Unfortunately, there are some conflicts between methos signature of the Set interface and the Map interface in Java. I’ve finally chosen to implements only the Set interface and to add the Map method without implementing this interface.
Do you see a nicer solution?
In response to the first comments, here is my goal:
Have a set structure and be able to efficiently access to a subset of values of this set, corresponding to a given key value. At the beginning I instantiated a map and a set, but I tried to joined the two structures to optimize performances.
Perhaps you could add more information which operations do you really want. I guess you want to create a set which automatically groups their elements by a key, right? The question is which operations do you want to be able to have? How are elements added to the Set? Can elements be deleted by removing them from a grouped view? My proposal would be an interface like that:
If you want to be able to use the Set as map you can add another method
That avoids the use of multiple interface inheritance and the resulting problems.