Class Reflect


  • public final class Reflect
    extends java.lang.Object

    A series of basic Reflect based utility functions. In most cases, exceptions thrown by the Reflect API methods are caught and ignored choosing to return an Optional with no value instead.

    Since:
    2.2.1
    Version:
    2.2.1
    Author:
    Michael Grove
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> com.google.common.base.Optional<java.lang.Class<T>> getClass​(java.lang.String theClassName)
      Returns the class with the given name.
      static <T> com.google.common.base.Optional<java.lang.reflect.Constructor<T>> getConstructor​(java.lang.Class<T> theClass, java.lang.Class<?>... theArgTypes)
      Get the constructor of the class with the given arguments.
      • Methods inherited from class java.lang.Object

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

      • getClass

        public static <T> com.google.common.base.Optional<java.lang.Class<T>> getClass​(java.lang.String theClassName)
        Returns the class with the given name. A ClassNotFoundException will not be thrown if the class does not exist, an Optional with an absent value will be returned instead. Similarly, if a ClassCastException is thrown, because the class name is valid, but is not of the correct type of class requested by the user, an Optional without a value will be returned..
        Parameters:
        theClassName - the class name
        Returns:
        the class, or null if it does not exist
      • getConstructor

        public static <T> com.google.common.base.Optional<java.lang.reflect.Constructor<T>> getConstructor​(java.lang.Class<T> theClass,
                                                                                                           java.lang.Class<?>... theArgTypes)
        Get the constructor of the class with the given arguments. NoSuchMethodException is not thrown if a suitable constructor does not exist, an Optional without a value is returned.
        Type Parameters:
        T - the class type
        Parameters:
        theClass - the class to get the constructor of
        theArgTypes - the arguments to the constructor
        Returns:
        the constructor, an Optional with an absent value if the constructor does not exist