Class TypeLoader


  • public final class TypeLoader
    extends java.lang.Object
    Understands loading a class dynamically using a specific ClassLoader.
    Since:
    1.1
    Author:
    Alex Ruiz
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<?> load()
      Loads the class with the name specified in this type, using this class' ClassLoader.
      <T> java.lang.Class<? extends T> loadAs​(java.lang.Class<T> type)
      Loads the class with the name specified in this type, as the given type, using this class' ClassLoader.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • load

        public java.lang.Class<?> load()
        Loads the class with the name specified in this type, using this class' ClassLoader.

        Example:

         Class<?> type = type("org.republic.Jedi").withClassLoader(myClassLoader).load();
         

        Returns:
        the loaded class.
        Throws:
        ReflectionError - wrapping any error that occurred during class loading.
      • loadAs

        public <T> java.lang.Class<? extends T> loadAs​(java.lang.Class<T> type)
        Loads the class with the name specified in this type, as the given type, using this class' ClassLoader.

        The following example shows how to use this method. Let's assume that we have the class Jedi that extends the class Person:

         Class<Person> type = type("org.republic.Jedi").withClassLoader(myClassLoader).loadAs(Person.class);
         

        Type Parameters:
        T - the generic type of the type.
        Parameters:
        type - the given type.
        Returns:
        the loaded class.
        Throws:
        java.lang.NullPointerException - if the given type is null.
        ReflectionError - wrapping any error that occurred during class loading.