このエラーに遭遇しましたが、問題を見つけることができません。
The method compute(Set<String>, Set<String>)
in the type JaccardSimilarity<String> is not applicable
for the arguments (Set<String>, Set<String>)
問題の方法はジェネリックスを使用しています:
public class JaccardSimilarity<E> implements SimilarityMeasure<Set<E>, Set<E>> {
@Override
public double compute(Set<E> s1, Set<E> s2){
// compute some stuff
return unionSize == 0 ? 1 : intersectionSize / (double)unionSize;
}
}
私はそれを私のクラスで次のように呼んでいます:
public MyClass {
private JaccardSimilarity<String> sim = new JaccardSimilarity<String>();
public void calc() {
Set<String> s1 = new HashSet<>();
s1.add("hallo welt");
Set<String> s2 = new HashSet<>();
s2.add("hallo welt");
// the line below throws the error..
double result = sim.compute(s1, s2);
}
Java Genericsについての私の謙虚な理解では、これは完全に有効なコードです...
これはどのように可能ですか?
編集-追加コード:
public interface SimilarityMeasure<Q, R> extends RelevanceFunction<Q, R> {}
と..
public interface RelevanceFunction<Q, R> {
public double compute(Q v1, R v2);
}
編集2:インポートは次のとおりです。
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import <redacted>.JaccardSimilarity;
編集3:これはエラーでした:
import <redacted>.representation.Set;
微妙...