0

So i have two methods. One that takes a Set as an argument and the other is an overloaded version of the same thing. For some reason when I call:

returnMap = getWordLengthMap(returnMap, itr);


It tells me that the overloaded function doesn't support the arguments. It is essentially telling me that it can't take a TreeMap or TreeSet as arguments for Map or Set? idk what im doing wrong.

public static Map<Integer, Set<String>> getWordLengthMap(Set<String> theSet) {
    TreeMap<Integer, TreeSet<String>> returnMap = 
            new TreeMap<Integer, TreeSet<String>>();
    Iterator<String> itr = theSet.iterator();
    returnMap = getWordLengthMap(returnMap, itr);

}


/**
 * Description: Overloaded recursive method
 * @param theWordLengths Map containing word lengths
 * @param theWordSetItr Iterator for Strings in map
 * @return Map
 */
public static Map<Integer, Set<String>> getWordLengthMap(
        Map<Integer, Set<String>> theWordLengths,
        Iterator<String> theWordSetItr) {
    return null; //placeholder
}
Jacob R
  • 327
  • 2
  • 11
  • That answer on the other post does not answer my question. Why can't I feed a TreeMap> into the argument of Map>? – Jacob R Feb 26 '17 at 22:58
  • Because, just like a List is not a List, a Map> is not a Map>. You can put any kind of Set in the latter, but you can only put TreeSet in the former. The duplicate does answer your question. Read it again. – JB Nizet Feb 26 '17 at 23:12
  • ahh. ok that makes sense I guess. Was taught different in class. Professor told me that if you have a Set for example you can put a TreeSet or HashSet as an argument for Set. – Jacob R Feb 26 '17 at 23:14
  • Your teacher was right. You can do that. Because a TreeSet is a Set. What you can't do is put a List as an argument for a List. That's different. To make a car analogy, a Car is a Vehicle. So a garage that accepts any vehicle will accept cars. But a road accepting cars only is not a road accepting vehicles only. Because on a road accepting vehicles only, you can drive a motorcycle. But you can't do that on a road accepting cars only. – JB Nizet Feb 26 '17 at 23:23
  • Thanks that explanation really helped. – Jacob R Feb 26 '17 at 23:51

0 Answers0