D
Daniel Dyer
When using generics with multiple bounds, like this:
private <T extends List & Serializable> void method(T t)
{
// Do something.
}
It seems that this method is useless to me without knowing, in advance,
the concrete type of T. What I really want is to be able to cast to a
type intersection. For example:
method((List & Serializable) myObject)
But, of course, this isn't legal. It appears that the only option is to
write a wrapper that implements both interfaces and use that.
Unless there's something I've missed... (I'm not actually interested in
serializable lists, it's just the simplest example)
Dan.
private <T extends List & Serializable> void method(T t)
{
// Do something.
}
It seems that this method is useless to me without knowing, in advance,
the concrete type of T. What I really want is to be able to cast to a
type intersection. For example:
method((List & Serializable) myObject)
But, of course, this isn't legal. It appears that the only option is to
write a wrapper that implements both interfaces and use that.
Unless there's something I've missed... (I'm not actually interested in
serializable lists, it's just the simplest example)
Dan.