我有这样的方法泛型作为Java中的泛型类型?
static public <K> float calculateSimilarity(HashMap<K, Float> hashMap1, Class<K> clazz)
在我把这种方法是这样的部分:
HashMap<Pair<Long,Long>,Float> newValues1=....; //A.K.A. K is Pair<Long,Long> type.
calculateSimilarity(newValue1, Pair.class); // Doesn't work here!
,其中对被
org.apache.commons.lang3.tuple .Pair
由两个元素组成的一对。
请问在调用calculateSimilarity方法时如何使用Pair.class?因为如果我使用字符串作为K它的工作,但在这里配对它不起作用我得到了错误。
您想告诉我们编译错误是什么,或者我们必须猜测? –
Eclipse只是说“方法XXX不适用于参数XXX”没有别的...... –