S
Simon Brooke
I've been writing Java since Java 1.0, but three years ago I was switched
to the dark side, so I've been writing C# for a while; I'm refreshing my
Java skills and am certainly rusty. If this is a silly question please do
say so.
I'm trying to build a tiered map, such that when the map is searched for
a key, each tier is searched successively starting from the top one until
a value is found; in this way upper-tier key/value pairs can mask key/
value pairs in lower layers.
So I've started out:
/**
* A tiered map is a bit like a wedding cake. Each layer contains
* key/value pairs which mask key/value pairs in lower layers.
* @author simon
*
* @param <K> The class of which keys in this tiered map are members
* @param <V> The class of which values in this tiered map are members
*/
public class TieredMap<K,V> extends LinkedList<Map<K,V>> implements
Map<K,V>
Things all go swimmingly until I get to the method Remove(Object key).
The Map interface wants
public V remove(Object key)
but the superclass wants
public boolean remove( Object key)
Is there any way in which both can be satisfied?
Yes, I appreciate that the alternative would be to make TieredMap extend
Object and store the list of tiers a private instance variable; but that
seems a bit clunky. Is there a generic (pun intended) solution to this
problem?
to the dark side, so I've been writing C# for a while; I'm refreshing my
Java skills and am certainly rusty. If this is a silly question please do
say so.
I'm trying to build a tiered map, such that when the map is searched for
a key, each tier is searched successively starting from the top one until
a value is found; in this way upper-tier key/value pairs can mask key/
value pairs in lower layers.
So I've started out:
/**
* A tiered map is a bit like a wedding cake. Each layer contains
* key/value pairs which mask key/value pairs in lower layers.
* @author simon
*
* @param <K> The class of which keys in this tiered map are members
* @param <V> The class of which values in this tiered map are members
*/
public class TieredMap<K,V> extends LinkedList<Map<K,V>> implements
Map<K,V>
Things all go swimmingly until I get to the method Remove(Object key).
The Map interface wants
public V remove(Object key)
but the superclass wants
public boolean remove( Object key)
Is there any way in which both can be satisfied?
Yes, I appreciate that the alternative would be to make TieredMap extend
Object and store the list of tiers a private instance variable; but that
seems a bit clunky. Is there a generic (pun intended) solution to this
problem?