Package com.pnfsoftware.jeb.util.reflect
Class ReflectionHelper
java.lang.Object
com.pnfsoftware.jeb.util.reflect.ReflectionHelper
Helper routines using the Java Reflection API.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
static boolean
hasNoArgConstructor
(Class<?> c) static <T> T
instantiateSafe
(Class<? extends T> c) static Object
static boolean
isInstance
(Object o, Class<?>... classObjects) A multi-element variant ofClass.isInstance(Object)
.static <T> boolean
isInstance
(Object o, Collection<Class<? extends T>> classObjects) A multi-element variant ofClass.isInstance(Object)
.static Object
newInstance2
(Constructor<?> constructor) static Class<?>
reduceDimensions
(Class<?> c) Reduce dimensions of an array type.static Class<?>
removeDimensions
(Class<?> c) Remove dimensions of an array type.static void
static boolean
Determine if a type is a descendant of the provided ancestor.
-
Constructor Details
-
ReflectionHelper
public ReflectionHelper()
-
-
Method Details
-
hasNoArgConstructor
-
newInstance2
public static Object newInstance2(Constructor<?> constructor) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException -
invoke2
public static Object invoke2(Method m, Object o, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException -
set2
public static void set2(Field f, Object o, Object value) throws IllegalAccessException, IllegalArgumentException -
get2
public static Object get2(Field f, Object o) throws IllegalAccessException, IllegalArgumentException -
removeDimensions
Remove dimensions of an array type.- non-array => non-array
- type[]...[] => type
- Parameters:
c
- a type- Returns:
- the dimension-less type
-
reduceDimensions
Reduce dimensions of an array type. Careful, caveat for primitives:- non-array => non-array
- Object[]...[] => Object
- prim[]...[] => prim[]
- Parameters:
c
- a type- Returns:
-
instantiateSafe
- Parameters:
c
-- Returns:
-
isInstance
A multi-element variant ofClass.isInstance(Object)
.- Parameters:
o
- the object to be testedclassObjects
- a collection ofClass
objects- Returns:
- true if o can be cast to one of the provided class objects
-
isInstance
A multi-element variant ofClass.isInstance(Object)
.- Parameters:
o
- the object to be testedclassObjects
- a collection ofClass
objects- Returns:
- true if o can be cast to one of the provided class objects
-
subtypeOf
Determine if a type is a descendant of the provided ancestor.- Parameters:
c
- a type (class or interface)parent
- a candidate ancestor type (class or interface)- Returns:
- true or false
-