【发布时间】:2009-07-11 18:44:09
【问题描述】:
我有几种是这样的
// a value that is aware of its key type (K)
Bar<K>
// something that deals with such values and keys
Foo<V extends Bar<K>, K>
如何重新创建 Foo 以便您可以在 Guice 中使用它?我坚持的一点是如何将 K 从 Bar 交叉引用到 Foo 的第二个参数化类型。
例如,
WildcardType kType = Types.subtypeOf(Object.class);
WildcardType barType =
Types.subtypeOf(Types.newParameterizedType(Bar.class, pipeKey));
ParameterizedType fooType =
Types.newParameterizedType(Foo.class, pipelineableType, pipeKey);
这似乎是错误的,因为它基本上是:
Foo<V extends Bar<? extends Object>, ? extends Object>
这与以下内容不同:
Foo<V extends Bar<K>, K>
在后一种情况下,我知道 K 是一致类型。
有什么想法吗?
干杯
马特
【问题讨论】:
标签: generics reflection runtime guice