What’s the reason I can’t create generic array types in Java?

What’s the reason why Java doesn’t allow us to do

private T[] elements = new T[initialCapacity];

I could understand .NET didn’t allow us to do that, as in .NET you have value types that at run-time can have different sizes, but in Java all kinds of T will be object references, thus having the same size (correct me if I’m wrong).

What is the reason?

17 Answers
17

Leave a Comment