开发者

Problems with java reflection

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.g开发者_C百科etClass() );
              ^

I need help.

Thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜