私は初心者に過ぎず、私を助けてくれる良い魂が欲しいです;)私はこの方法を手に入れました:
( (HashSet<String>) pos[targetPos]).add(word);
それは私に例外を与えます
(Unchecked cast from Object to HashSet<String>)
Object[pos] を String[pos] に変更してより具体的にしようとしましたが、次の行にエラーが表示されます。pos[targetPos] = new HashSet<String>();
Type mismatch: cannot convert from HashSet<String> to String
これは方法です:
public void add(String word, Object[] root){
Object[] pos = root;
int wordIndex = 0;
int targetPos;
if(word.length()>=3){
for(int i = 1; i <=3; i++){
targetPos = word.charAt(wordIndex) -'a'; //convert a letter into index eg a==0
if(i==3){
if(pos[targetPos]==null){
pos[targetPos] = new HashSet<String>();
}
( (HashSet<String>) pos[targetPos]).add(word);
//System.out.println(Arrays.toString(pos));
break;
}//end if outer if
else{
if(pos[targetPos]==null){
pos[targetPos] = new Object[28];
}
wordIndex++;
pos = (Object[]) pos[targetPos];
}
}//end of for
}
}
ルートは
Object[] root = new Object[28];