Suppose, you have to call very often operation T get(int) which returns an object from the underlying array. Basically, this can be implemented in two ways:
class GenericArray<T> {
final T[] underlying;
GenericArray(Class<T> clazz, int length) {
underlying = (T[]) Array.newInstance(clazz, length);
}
T get(int i) { return underlying[i]; }
}
and
class ObjectArray<T> {
final Object[] underlying;
ObjectArray(int length) {
underlying = new Object[length];
}
T get(int i) { return (T) underlying[i]; }
}
The first one is using reflection, so it would be slower at creation time. The second one is using downcasting which introduces some overhead. Due of generic type erasure at runtime, there has to be some implicit casting mechanism.
So is it true, that these two are equal when it comes to get(i)?
+++I see I was wrong this time: When the byte is exactly the same, then it is relevant.