Determine the class hierarchy of a class My only concern with the following class is the line hierarchy.trimToSize() in determineHierarchy, because it is not necessary for determining the class hierarchy. However, putting it in the constructor clutters the code more than my current solution. Any recommendations or should I just live with it?

Since this class is completely finished and tested, I also look for any other helpful comments. The target version is 1.8.

/** The class hierarchy of a class. */
public class ClassHierarchy {

    private final List&lt;Class&lt;?&gt;&gt; hierarchy;

    /**
     * Creates a ClassHierarchy instance for the given class {@literal clazz}.
     * 
     * @param clazz
     *            Class for which the class hierarchy should be determined. Must not be null and must refer to a class
     *            type.
     * 
     * @throws IllegalArgumentException
     *             if {@literal clazz} does not refer to a class type
     * @throws NullPointerException
     *             if {@literal clazz} is null
     */
    public ClassHierarchy(Class&lt;?&gt; clazz) {
        validateConstructorArgument(clazz);
        hierarchy = Collections.unmodifiableList(determineHierarchy(clazz));
    }

    /**
     * Returns the class hierarchy as an immutable list.
     * 
     * &lt;p&gt;
     * The classes are ordered, starting with the class for which the instance was created and ending with
     * {@code Object.class}.
     * 
     * @return the class hierarchy as an immutable list.
     */
    public List&lt;Class&lt;?&gt;&gt; getHierarchy() {
        return hierarchy;
    }

    private static void validateConstructorArgument(Class&lt;?&gt; clazz) {
        Objects.requireNonNull(clazz, "clazz must not be null");

        if (clazz.isEnum() || clazz.isAnnotation() || clazz.isInterface() || clazz.isArray() || clazz.isPrimitive()) {
            throw new IllegalArgumentException("clazz must refer to a class type");
        }
    }

    private static ArrayList&lt;Class&lt;?&gt;&gt; determineHierarchy(Class&lt;?&gt; clazz) {
        ArrayList&lt;Class&lt;?&gt;&gt; hierarchy = new ArrayList&lt;&gt;();
        for (Class&lt;?&gt; currentClass = clazz; currentClass != null; currentClass = currentClass.getSuperclass()) {
            hierarchy.add(currentClass);
        }
        hierarchy.trimToSize();
        return hierarchy;
    }

}
The one comment I have is that I find your if statement to be really hard to read:

if (clazz.isEnum() || clazz.isAnnotation() || clazz.isInterface() || clazz.isArray() || clazz.isPrimitive()) 


I would at least put that into a small helper to throw that exception:

private void checkClassRefersToClassType()