Point to a hashSet

advertisements

How would I write an if statement that says: if pos2[targetPos3] doesn't point to a hashset (is not a hashset) ? I tried that but it still gives me a null point exception.

Object[] pos2;
int targetPos3;
targetPos3 = word.charAt(2) - 'a';

if(pos2[targetPos3] != (HashSet<String>) pos2[targetPos3]){
   System.out.println("Sorry");
 }


Try this:

if(!(pos2[targetPos3] instanceof HashSet)){
    System.out.println("Sorry");
}

There is no way to see if it's a HashSet of String (or any other type for that matter) because of type erasure.