java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.HashSet
我在行 出现错误: (HashSet<String>) pos[targetPos3]).contains(word)
。
public void search(String word, Object[] root){
int targetPos1;
int targetPos2;
Object[] pos = root;
targetPos1 = word.charAt(0) -'a';
targetPos2 = word.charAt(1) -'a';
int targetPos3 = word.charAt(2) - 'a';
if(root[targetPos1]==null){
System.out.println("1st letter NOT FOUND");
}
else{
pos = (Object[]) root[targetPos1];
if(pos[targetPos2]==null){
System.out.println("2nd letter NOT FOUND");
}
else{
if( ((HashSet<String>) pos[targetPos3]).contains(word)){
System.out.println("Word FOUND: " + word);
System.out.println(pos[targetPos3]);//output children
}
else{
System.out.println("NOT FOUND");
}
}
}//end of else
}