For example,
I'm trying to initialize a generic array of class Node<E>
.
Node<Integer>[] nodes =(Node<Integer>[])new Node[10];
Is this a good practice? If not, what is a better way of doing this?
For example,
I'm trying to initialize a generic array of class Node<E>
.
Node<Integer>[] nodes =(Node<Integer>[])new Node[10];
Is this a good practice? If not, what is a better way of doing this?
This is the quick and dirty way to do it. There are other methods that are more "safe" so to speak. You can find them in a previously answered question here: How to create a type safe generic array in java?