Note that there are some explanatory texts on larger screens.

plurals
  1. POstrange Java generics compilation error: parameterized method is not applicable for same parameterized types?
    primarykey
    data
    text
    <p>I've stumbled across this error and I can't find the problem:</p> <pre><code>The method compute(Set&lt;String&gt;, Set&lt;String&gt;) in the type JaccardSimilarity&lt;String&gt; is not applicable for the arguments (Set&lt;String&gt;, Set&lt;String&gt;) </code></pre> <p>The method in question is using Generics: </p> <pre><code>public class JaccardSimilarity&lt;E&gt; implements SimilarityMeasure&lt;Set&lt;E&gt;, Set&lt;E&gt;&gt; { @Override public double compute(Set&lt;E&gt; s1, Set&lt;E&gt; s2){ // compute some stuff return unionSize == 0 ? 1 : intersectionSize / (double)unionSize; } } </code></pre> <p>I'm calling it in my class this way: </p> <pre><code>public MyClass { private JaccardSimilarity&lt;String&gt; sim = new JaccardSimilarity&lt;String&gt;(); public void calc() { Set&lt;String&gt; s1 = new HashSet&lt;&gt;(); s1.add("hallo welt"); Set&lt;String&gt; s2 = new HashSet&lt;&gt;(); s2.add("hallo welt"); // the line below throws the error.. double result = sim.compute(s1, s2); } </code></pre> <p>In my humble understanding of Java Generics this is perfectly valid code...</p> <p>How is this possible? </p> <p>Edit - Additional Code: </p> <pre><code>public interface SimilarityMeasure&lt;Q, R&gt; extends RelevanceFunction&lt;Q, R&gt; {} </code></pre> <p>and..</p> <pre><code>public interface RelevanceFunction&lt;Q, R&gt; { public double compute(Q v1, R v2); } </code></pre> <p>Edit 2: Here are the Imports: </p> <pre><code>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 &lt;redacted&gt;.JaccardSimilarity; </code></pre> <p>Edit 3: This was the error: </p> <pre><code>import &lt;redacted&gt;.representation.Set; </code></pre> <p>subtle...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload