In the below syntax from java.util.HashMap
, Generic type parameters are used for type casting after instantiating a raw type array,
Node<K,V>[] newTab = (Node<K,V>[])new Node[newCap];
Similar code does not compile here with similar syntax(as shown below), giving error: Type safety: Unchecked cast from Node[] to Node<K,V>[]
public class NestedInterfaceInInterface {
public static void main(String[] args) {
Node<K,V>[] newTab = (Node<K,V>[])new Node[10];
//Node<String,String>[] newTab = (Node<String,String>[])new Node[10]; // this works
}
}
1) How do I resolve this error ?
2) How syntax Node<K,V>[] newTab = (Node<K,V>[])new Node[10];
different from Node<String,String>[] newTab = (Node<String,String>[])new Node[10];
?