@SuppressWarnings("unchecked")
public <X, Y> TypeToken<T> where(TypeParameter2<X> typeParam1,
TypeToken<X> typeArg1, TypeParameter2<Y> typeParam2, TypeToken<Y> typeArg2) {
// resolving both parameters in one shot seems to work around 1635
TypeResolver resolver = new TypeResolver();
// where(Map) is package-private in TypeResolver
Invokable<TypeResolver, TypeResolver> whereWithMap =
Reflection2.<TypeResolver, TypeResolver>method(TypeResolver.class, "where",
Map.class);
try {
resolver = whereWithMap.invoke(resolver, ImmutableMap.of(
typeParam1.getTypeVariable(), typeArg1.getType(),
typeParam2.getTypeVariable(), typeArg2.getType()));
} catch (IllegalAccessException exception) {
// should never happen
throw new IllegalStateException(exception);
} catch (InvocationTargetException exception) {
// should never happen
throw new IllegalStateException(exception);
}
return (TypeToken<T>) TypeToken.of(resolver.resolveType(getType()));
}