Package com.complexible.common.base
Class Reflect
java.lang.Object
com.complexible.common.base.Reflect
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
Modifier and TypeMethodDescriptionstatic <T> com.google.common.base.Optional<Class<T>> Returns the class with the given name.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.
-
Method Details
-
getClass
Returns the class with the given name. A ClassNotFoundException will not be thrown if the class does not exist, anOptionalwith 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, anOptionalwithout a value is returned.- Type Parameters:
T- the class type- Parameters:
theClass- the class to get the constructor oftheArgTypes- the arguments to the constructor- Returns:
- the constructor, an Optional with an absent value if the constructor does not exist
-