java反射的问题
在 Combinator 类中:
public static <KEY, T> void getCombsIntoTreeMap(int N, int K,
TreeMap<KEY, T> map,
Class<? extends KEY> keyIstance,
Class<? extends T> valueIstance)
{...}
和在 Comp 类中;
TreeMap<Hand, int[]> mappa = new TreeMap<Hand, int[]>();
int[] keyIstance = new int[2];
Hand valueIstance = new Hand( new int[]{0} );
Combinator.getCombsIntoTreeMap(53, 5, mappa,
keyIstance.getClass(),
valueIstance.getClass() );
;
编译器只是说:
Comp.java:85: <KEY,T>getCombsIntoTreeMap(int,int,java.util.TreeMap<KEY,T>,java.lang.Class<? extends KEY>,java.lang.Class<? extends T>) in Combinator cannot be applied to (int,int,java.util.TreeMap<Hand,int[]>,java.lang.Class<capture#86 of ? extends int[]>,java.lang.Class<capture#138 of ? extends Hand>)
Combinator.getCombsIntoTreeMap(53, 5, mappa, keyIstance.getClass(), valueIstance.getClass() );
^
我需要帮助。
谢谢
in Combinator class:
public static <KEY, T> void getCombsIntoTreeMap(int N, int K,
TreeMap<KEY, T> map,
Class<? extends KEY> keyIstance,
Class<? extends T> valueIstance)
{...}
and in Comp class;
TreeMap<Hand, int[]> mappa = new TreeMap<Hand, int[]>();
int[] keyIstance = new int[2];
Hand valueIstance = new Hand( new int[]{0} );
Combinator.getCombsIntoTreeMap(53, 5, mappa,
keyIstance.getClass(),
valueIstance.getClass() );
;
the compiler just says:
Comp.java:85: <KEY,T>getCombsIntoTreeMap(int,int,java.util.TreeMap<KEY,T>,java.lang.Class<? extends KEY>,java.lang.Class<? extends T>) in Combinator cannot be applied to (int,int,java.util.TreeMap<Hand,int[]>,java.lang.Class<capture#86 of ? extends int[]>,java.lang.Class<capture#138 of ? extends Hand>)
Combinator.getCombsIntoTreeMap(53, 5, mappa, keyIstance.getClass(), valueIstance.getClass() );
^
I need help.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您的 Map 实例具有类型参数列表
,并且您的函数首先需要“KEY”类,然后是“T”类,但是您以错误的顺序将类传递到函数中。换句话说,您的地图声明时“KEY”为“Hand”,值为“int[]”,但您的“keyIstance”(顺便说一句应该是“Instance”)的类型为
int[]
这似乎是倒退的。Well your
Map
instance has the type parameter list<KEY, T>
, and your function wants the "KEY" class first and the "T" class second, but you're passing the classes into the function in the wrong order.In other words, your map is declared with the "KEY" being "Hand" and the value being "int[]", but your "keyIstance" (should be "Instance" by the way) has type
int[]
and that seems backwards.