【发布时间】:2014-10-17 11:00:17
【问题描述】:
请在java中使用新的。
我正在尝试理解泛型,直到我明白这一点:
Pair<Integer, GenericBox<String>> p2 = new OrderedPair<>(1, new GenericBox<>("Parametized Type");
p2.print();
打印方式:
public void print() {
System.out.println(this.key + ", " + this.value);
}
它工作正常,除非我使用参数化类型参数。
样本输出:
1, GenericBox@41171d93
预期输出:
1, Parametized Type
试过这个:How to get type parameter values using java reflection? 但它只给了我 K,它是 OrderedPair 中的一个参数''
这是我在这里的第一个问题,如果有什么我错过或不清楚的地方,非常感谢反馈。
【问题讨论】:
-
你需要覆盖你的 GenericBox 类的 toString