Is it possible to cast an object in Java to a combined generic type?
I have a method like:
public static void doSomet
It is possible to "up-cast" to a union type, by the horrible means of encoding the union type into a method's type parameter; for your example you can write
private Q upcast(final Object in) {
return (Q) in;
}
// ... elsewhere...
if (myObject instanceof Foo && myObject instanceof Bar) {
doSomething(upcast(myObject));
}