There are good reasons for why you are struggling to do what you want. Basically they boil down to the fact that what you want to do will not be type safe. If you managed to create an array of type BST<T>[]
, it would be an array whose members could have different types (e.g. BST<Integer>
and BST<Float>
).
You can use an object array and then check the instance type of the member (using instanceof) and cast it when you use it in your program, but that is effectively working around the strong typing of Java, which i wouldn't recommend unless it's absolutely unavoidable in your circumstance. The coding approach would be similar to (though not exactly the same as) the second option described in this answer, which I recommend you have a look at.
This issue is discussed in Oracle's restrictions on generic types. There are similar questions on here (and here), although they are not exactly duplicates as they tend to be asking about using the generic type <T>
as the type of the array.
I suggest you use an ArrayList to do what you want. That would seem like the approach that would be more compatible with generics.