Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are right that a <code>TrieEntry&lt;T&gt;</code> is a <code>Map.Entry&lt;String, T&gt;</code>. A <code>HashSet&lt;TrieEntry&lt;T&gt;&gt;</code> is also a <code>Set&lt;TrieEntry&lt;T&gt;&gt;</code>, but it is <strong>not</strong> a <code>Set&lt;Map.Entry&lt;String, T&gt;&gt;</code>.</p> <p>If it were you could do this:</p> <pre><code>Set&lt;TrieEntry&lt;T&gt;&gt; trieSet = ...; Set&lt;Map.Entry&lt;String, T&gt;&gt; mapSet = trieSet; mapSet.add(mapEntry); </code></pre> <p>So now trieSet would now contain a <code>Map.Entry&lt;String, T&gt;</code>! This would break generics.</p> <p>So how to solve this particular problem? Easy - use a bounded wildcard:</p> <pre><code>Set&lt;? extends Map.Entry&lt;String, T&gt;&gt; x = new HashSet&lt;TrieEntry&lt;T&gt;&gt;(); </code></pre> <p>You can read <code>? extends Map.Entry&lt;String, T&gt;</code> as "anything which is at least a <code>Map.Entry&lt;String, T&gt;</code>".</p> <hr> <p>Okay, now to your implementation problem. I actually believe, that this is <strong>not solveable</strong> in this way because of the current definition of the method entrySet(). It <em>should</em> return <code>? extends Map.Entry&lt;String, T&gt;</code>, but it <em>does</em> return <code>Map.Entry&lt;String, T&gt;</code>.</p> <p>There is actually a <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231312" rel="nofollow">bug report</a> (or feature request) for exactly this problem. Looking at the submit date and the priority, a fix can't be expected soon.</p> <p>So you have two options:</p> <ol> <li><p>Drop your <code>TrieEntry</code> class and try to use <code>Map.Entry</code> instead, storing information in your keys and/or values.</p></li> <li><p>Drop the <code>Map</code> interface and let your custom <code>entrySet</code> method return <code>? extends Map.Entry&lt;String, T&gt;</code>.</p></li> </ol> <p>Both solutions may not be ideal, and there may be better solutions, but this is all what I currently can tell you.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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