Class Reflect

java.lang.Object
com.complexible.common.base.Reflect

public final class Reflect extends 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 Details

    • getClass

      public static <T> com.google.common.base.Optional<Class<T>> getClass(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<Constructor<T>> getConstructor(Class<T> theClass, 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