오류 : java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.HashSet
줄에 (HashSet<String>) pos[targetPos3]).contains(word)
이 있습니다.클래스 캐스팅 예외 HashSet
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
}
어디에서이 메서드를 호출합니까? 루트 란 무엇입니까? – BobTheBuilder