R
R
rvller2012-04-08 23:58:25
Java
rvller, 2012-04-08 23:58:25

Java template implementation?

Did it like this:

public class Trie<T> implements Map<String, T> {
    private class TrieEntry<S> implements Map.Entry<String, S> {
        // stupid implementation here
    }
    // uninterested code here
}

All OK.
But when describing the entrySet() method:
public Set<java.util.Map.Entry<String, T>> entrySet() {
    Set<java.util.Map.Entry<String, T>> x = new HashSet<TrieEntry<T>>();
    // some uninterested code here
}

Eclipse reacts like this:
"Type mismatch: cannot convert from HashSet<Trie.TrieEntry> to Set<Map.Entry<String,T>>"
Where am I wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artyushov, 2012-04-09
@Artyushov

If A extends B does not mean that Set extends Set You can just write
Set<java.util.Map.Entry<String, T>> x = new HashSet<java.util.Map.Entry<String, T>>( );
and put your implementation there.

S
SergeyGrigorev, 2012-04-09
@SergeyGrigorev

Try this
Set<? extends java.util.Map.Entry<String, T>> x = new HashSet<TrieEntry>();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question