I have a good understanding of data structures and can happily implement them in C++ without issue; I get a little tripped up in Java though due to the generic implementation constraints.
Specifically, I get confused when I'm trying to create a data structure backed by an array. I know, for example, that I cannot do this:
public class HashTable<T> {
private T[] table;
public HashTable() {
table = new T[10]; //Type param T cannot be instantiated directly.
}
}
I also know that if I back my generic array list with an object array, I'm going to have to suppress a number of "unchecked cast" warnings which seems of ill form.
What is the best way to create an array-based data structure in Java? Is there some trick that can be used to do it in a cleaner manner than just creating a straight object array and dealing with the messy casting?