I can have a template class of type T in C++, just like java, but in C++ I can do this
T array = new T;
in java, if I do that, I get an error saying that I'm not allowed to use generic arrays.
A lot of things like JTables and stuff allowed Vectors to be passed. Vectors were changing in size. Arrays aren't by nature.
However, it seems Vector has become deprecated (or is close. Why Stack, which extends Vector, is still fine is a mystery to me. You'd think if a superclass became deprecated, its subclasses would also be affected by that.)
I can use ArrayList and the toArray() method but it always must return an array of type Object.
Hence, I might possibly run into trouble with typecasting issues (or so it seemed).
I want to know how I can fix this so that it returns the type I need without having to do lots of type casting.
Also, why doesn't java allow generic arrays? It's based off of C++ or (maybe it was C) but C++ allows generic arrays. Why can't java?
Is it because of the fact that C++ doesn't really have any father superclass of all the classes but java has Object as the father superclass, hence preventing generic array or perhaps allowing it to return type Object and the creators of java used that since they were too lazy to bother with generic arrays or something, or is it something else?
Also, is the generic thing related to java's garbage collection as java might be confused as to what to garbage collect with a generic array whereas C++ leaves the cleanup of that up to the coder?