Map with values that are subclasses of keys?
How would one declare a Map whose values should be subclasses of its keys?
Naively, I thought I could do something like this (this fails, of course):
private <Textends SomeClass, Vextends T> Map<T, V> map;
Is this impossible?
Thanks,
Laird
[389 byte] By [
ljnelsona] at [2007-10-2 21:46:06]

> I don't think you can declare types in member
> declarations like that. Not sure though.
Yeah, you certainly can't for fields. You can? maybe? for methods? I seem to recall doing this, but can't be sure either.
> If you put the declaration for T and V in the class
> declaration, it works fine.
Yep. Unfortunately this field is a cache that backs another method. The class itself should not be constrained by these type parameters, and the caller should never really see them.
Oh well; another day, another generics shortcoming. :-)
Cheers,
Laird
> Yep. Unfortunately this field is a cache that backs
> another method. The class itself should not be
> constrained by these type parameters, and the caller
> should never really see them.
I'm having a hard time imagining what code will set the parameters to something concrete? What would do that, a subclass?