/** * @param implClassName class name to text * @return {@code true} if the class exists in the JVM and can be loaded */ public static boolean classExists(String implClassName) { try { forName(implClassName); return true; } catch (ClassNotFoundException ignored) { return false; } }
/** * @param className fully-qualified class name, which should be known to be available * @param <T> expected type of returned {@link Class} * @return {@link Class} for that named class */ public static <T> Class<T> loadClass(String className) { try { @SuppressWarnings("unchecked") Class<T> theClass = (Class<T>) forName(className); return theClass; } catch (ClassNotFoundException cnfe) { throw new IllegalStateException("No valid " + className + " exists", cnfe); } }
/** * @param className fully-qualified class name, which should be known to be available * @param superClass reference type of returned {@link Class} * @param <T> type of returned {@link Class} * @return {@link Class} for that named class */ public static <T> Class<? extends T> loadClass(String className, Class<T> superClass) { try { return forName(className).asSubclass(superClass); } catch (ClassNotFoundException cnfe) { throw new IllegalStateException("No valid " + superClass + " binding exists", cnfe); } }
/** * @param implClassName class name to text * @return {@code true} if the class exists in the JVM and can be loaded */ public static boolean classExists(String implClassName) { try { forName(implClassName); return true; } catch (ClassNotFoundException ignored) { return false; } }
/** * @param className fully-qualified class name, which should be known to be available * @param <T> expected type of returned {@link Class} * @return {@link Class} for that named class */ public static <T> Class<T> loadClass(String className) { try { @SuppressWarnings("unchecked") Class<T> theClass = (Class<T>) forName(className); return theClass; } catch (ClassNotFoundException cnfe) { throw new IllegalStateException("No valid " + className + " exists", cnfe); } }
/** * @param className fully-qualified class name, which should be known to be available * @param superClass reference type of returned {@link Class} * @param <T> type of returned {@link Class} * @return {@link Class} for that named class */ public static <T> Class<? extends T> loadClass(String className, Class<T> superClass) { try { return forName(className).asSubclass(superClass); } catch (ClassNotFoundException cnfe) { throw new IllegalStateException("No valid " + superClass + " binding exists", cnfe); } }