I was taking a look at this code.
What is this doing?
contents = (T)(new Object[DEFAULT_CAPACITY]) only serves to initialise
DEFAULT_CAPACITY number of
Object array is cast to
T since you cannot initialise generic arrays in Java. The cast of
T compiles and runs as all Java objects extend
It should be noted that the explicit cast of
T is considered unsafe and will result in a compiler warning. For more information on unchecked array casts in Java, see: Creating generic array in Java via unchecked type-cast.