Suppose we have a class Class<E> elementClass and we want to obtain the class of an array which would consist of elements of class elementClass. For years, java did not offer any elegant way of accomplishing this, so we have been instantiating a throwaway array just to get its class, like this:
Class<?> arrayClass = Array.newInstance( elementClass, 0 ).getClass();
This question: Getting the array Class<?> of a given class asked 4 years ago has an answer which shows precisely this inelegant method, and
This question: Java reflection getting array class of a given class asked 3 years ago shows an additional method which I am not sure is any less inelegant.
So, has anything improved in this regard in java during the last three years? Do we have any decent way of obtaining the class of an array given the class of the element?