Can't extend parameters in nested setup
Hi,
I've got some classes that look like:
publicclass WorkingSetCache<K, V>implements Runnable{...}
publicclass DatabaseCache<K, Vextends PersistentBusinessObject>extends WorkingSetCache<K, V>{...}
publicinterface Cacheable<K, Vextends PersistentBusinessObject >{}
I'd like to have the V in DatabaseCache be Cacheable with all the type safety from the basic declaration. But I'm not having any success figuring out what it should be. The code fragments above work, but then I have to doinstanceof and casts to use functions declared in Cacheable.
The semantics should be that you can declare a
DatabaseCache<Integer, Foo> theCache =new DatabaseCache<Integer, Foo>();
where Foo is a cachable, Persistant object, and there is an Integer key into the cache.
I'm clearly missing something, and would greatly appreciate pointers.
# 2
I'm not sure what your form, with the ampersand means.
What I am trying to do is to starting with
public class WorkingSetCache<K, V> implements Runnable {...}
public class DatabaseCache<K, V extends PersistentBusinessObject> extends WorkingSetCache<K, V> {...}
public interface Cacheable<K, V extends PersistentBusinessObject > {}
then have a class, say Resident which is declared as
public class Resident extends PersistentBusinessObject implements Cacheable<Integer, Resident> {}
This says that Resident is a PersistentBusinessObject and it is cachable, with the key being an Integer and the 'object' of the hashmap being a Resident
So the use/declaration of a parametered DatabaseCache would look like
DatabaseCache<Integer, Resident> theCache = new DatabaseCache<Integer, Resident>();
But with the declarations I have shown above, the
public class DatabaseCache<K, V extends PersistentBusinessObject>
only states that my "theCache" is using a Resident, which is a PersistentBusinessObject, while it is also Cachable.
The 'Cachable' part is lost, so I can't call the functions declared in the Cachable interface without an ugly cast.
Seems that proper declaration will let me say that V is both 'is a" PersistantBusinessObject and "implements" Cachable