Java Array Type Get arrayClass(Class compClass)

Here you can find the source of arrayClass(Class compClass)

Description

Return the array class that holds the specific component type.

License

Open Source License

Parameter

Parameter Description
compClass a parameter

Declaration

@SuppressWarnings("unchecked")
public static <T> Class<T[]> arrayClass(Class<T> compClass) 

Method Source Code

//package com.java2s;
// This package is part of the Spiralcraft project and is licensed under

public class Main {
    /**//from w w w.  j  a  v a2  s. co m
     * Return the array class that holds the specific component type.
     * 
     * @param compClass
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <T> Class<T[]> arrayClass(Class<T> compClass) {
        ClassLoader loader = compClass.getClassLoader();
        if (loader == null) {
            loader = Thread.currentThread().getContextClassLoader();
        }
        if (loader == null) {
            loader = ClassLoader.getSystemClassLoader();
        }
        if (loader == null) {
            throw new IllegalStateException("No classloader available");
        }
        try {
            return (Class<T[]>) Class.forName("[L" + compClass.getName() + ";", true, loader);
        } catch (ClassNotFoundException x) {
            throw new IllegalArgumentException(x);
        }
    }
}

Related

  1. arrayBaseClass(Class c)
  2. arrayClass(Class klass)
  3. arrayComponentClassFromArray(T[] arg)
  4. arrayElementIsObjectType(Class clazz)