emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[HW2] #128

Closed HallOfSam closed 4 years ago

HallOfSam commented 4 years ago

Hello! I encountered an error when doing HW2. I was trying to get all the values of a map of a TrieNode (i.e. all of the child nodes) and I wrote the following code: for ( TrieNode word : prefixRoot.getChildrenMap().values()).

The method getChildrenMap() returns a map consisting of children's characters as keys and their nodes as values, and values() returns a Collection view of the values contained in this map (which are all the child TrieNodes). However, I keep getting an error message that suggests the type of "word" should be an Object instead of TrieNode. Does anyone know that this might happen? (By the way, is there another way to access the child nodes of a TrieNodes other than the way I used?)

Thanks in advance.