/** * Determine whether the {@link Class} identified by the supplied name is present * and can be loaded. Will return {@code false} if either the class or * one of its dependencies is not present or cannot be loaded. * * @param className the name of the class to check * @param classLoader the class loader to use * (may be {@code null}, which indicates the default class loader) * @return whether the specified class is present */ public static boolean isPresent(String className, ClassLoader classLoader) { try { forName(className, classLoader); return true; } catch (Throwable ex) { // Class or one of its dependencies is not present... return false; } }
/** * Determine whether the {@link Class} identified by the supplied name is present * and can be loaded. Will return {@code false} if either the class or * one of its dependencies is not present or cannot be loaded. * * @param className the name of the class to check * @param classLoader the class loader to use * (may be {@code null}, which indicates the default class loader) * @return whether the specified class is present */ public static boolean isPresent(String className, ClassLoader classLoader) { try { forName(className, classLoader); return true; } catch (Throwable ex) { // Class or one of its dependencies is not present... return false; } }
/** * Determine whether the {@link Class} identified by the supplied name is present * and can be loaded. Will return {@code false} if either the class or * one of its dependencies is not present or cannot be loaded. * @param className the name of the class to check * @param classLoader the class loader to use * (may be {@code null}, which indicates the default class loader) * @return whether the specified class is present */ public static boolean isPresent(String className, ClassLoader classLoader) { try { forName(className, classLoader); return true; } catch (Throwable ex) { // Class or one of its dependencies is not present... return false; } }
/** * Resolve the given class name into a Class instance. Supports * primitives (like "int") and array class names (like "String[]"). * <p>This is effectively equivalent to the {@code forName} * method with the same arguments, with the only difference being * the exceptions thrown in case of class loading failure. * * @param className the name of the Class * @param classLoader the class loader to use * (may be {@code null}, which indicates the default class loader) * @return Class instance for the supplied name * @throws IllegalArgumentException if the class name was not resolvable * (that is, the class could not be found or the class file could not be loaded) * @see #forName(String, ClassLoader) */ public static Class<?> resolveClassName(String className, ClassLoader classLoader) throws IllegalArgumentException { try { return forName(className, classLoader); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Cannot find class [" + className + "]", ex); } catch (LinkageError ex) { throw new IllegalArgumentException( "Error loading class [" + className + "]: problem with class file or dependent class.", ex); } }
/** * Resolve the given class name into a Class instance. Supports * primitives (like "int") and array class names (like "String[]"). * <p>This is effectively equivalent to the {@code forName} * method with the same arguments, with the only difference being * the exceptions thrown in case of class loading failure. * * @param className the name of the Class * @param classLoader the class loader to use * (may be {@code null}, which indicates the default class loader) * @return Class instance for the supplied name * @throws IllegalArgumentException if the class name was not resolvable * (that is, the class could not be found or the class file could not be loaded) * @see #forName(String, ClassLoader) */ public static Class<?> resolveClassName(String className, ClassLoader classLoader) throws IllegalArgumentException { try { return forName(className, classLoader); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Cannot find class [" + className + "]", ex); } catch (LinkageError ex) { throw new IllegalArgumentException( "Error loading class [" + className + "]: problem with class file or dependent class.", ex); } }
/** * Resolve the given class name into a Class instance. Supports * primitives (like "int") and array class names (like "String[]"). * <p>This is effectively equivalent to the {@code forName} * method with the same arguments, with the only difference being * the exceptions thrown in case of class loading failure. * @param className the name of the Class * @param classLoader the class loader to use * (may be {@code null}, which indicates the default class loader) * @return Class instance for the supplied name * @throws IllegalArgumentException if the class name was not resolvable * (that is, the class could not be found or the class file could not be loaded) * @see #forName(String, ClassLoader) */ public static Class<?> resolveClassName(String className, ClassLoader classLoader) throws IllegalArgumentException { try { return forName(className, classLoader); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Cannot find class [" + className + "]", ex); } catch (LinkageError ex) { throw new IllegalArgumentException( "Error loading class [" + className + "]: problem with class file or dependent class.", ex); } }
Class<?> elementClass = forName(elementClassName, classLoader); return Array.newInstance(elementClass, 0).getClass(); Class<?> elementClass = forName(elementName, classLoader); return Array.newInstance(elementClass, 0).getClass(); Class<?> elementClass = forName(elementName, classLoader); return Array.newInstance(elementClass, 0).getClass();
Class<?> elementClass = forName(elementClassName, classLoader); return Array.newInstance(elementClass, 0).getClass(); Class<?> elementClass = forName(elementName, classLoader); return Array.newInstance(elementClass, 0).getClass(); Class<?> elementClass = forName(elementName, classLoader); return Array.newInstance(elementClass, 0).getClass();
Class<?> elementClass = forName(elementClassName, classLoader); return Array.newInstance(elementClass, 0).getClass(); Class<?> elementClass = forName(elementName, classLoader); return Array.newInstance(elementClass, 0).getClass(); Class<?> elementClass = forName(elementName, classLoader); return Array.newInstance(elementClass, 0).getClass();