public class

ReflectionHelper

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.reflect.ReflectionHelper

Class Overview

Helper routines using the Java Reflection API.

Summary

Public Constructors
ReflectionHelper()
Public Methods
static Object get2(Field f, Object o)
static boolean hasNoArgConstructor(Class<?> c)
static <T> T instantiateSafe(Class<? extends T> c)
static Object invoke2(Method m, Object o, Object... args)
static <T> boolean isInstance(Object o, Collection<Class<? extends T>> classObjects)
A multi-element variant of isInstance(Object).
static boolean isInstance(Object o, Class...<?> classObjects)
A multi-element variant of 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 set2(Field f, Object o, Object value)
static boolean subtypeOf(Class<?> c, Class<?> parent)
Determine if a type is a descendant of the provided ancestor.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ReflectionHelper ()

Public Methods

public static Object get2 (Field f, Object o)

Throws
IllegalAccessException
IllegalArgumentException

public static boolean hasNoArgConstructor (Class<?> c)

public static T instantiateSafe (Class<? extends T> c)

public static Object invoke2 (Method m, Object o, Object... args)

Throws
IllegalAccessException
IllegalArgumentException
InvocationTargetException

public static boolean isInstance (Object o, Collection<Class<? extends T>> classObjects)

A multi-element variant of isInstance(Object).

Parameters
o the object to be tested
classObjects a collection of Class objects
Returns
  • true if o can be cast to one of the provided class objects

public static boolean isInstance (Object o, Class...<?> classObjects)

A multi-element variant of isInstance(Object).

Parameters
o the object to be tested
classObjects a collection of Class objects
Returns
  • true if o can be cast to one of the provided class objects

public static Object newInstance2 (Constructor<?> constructor)

Throws
IllegalAccessException
IllegalArgumentException
InstantiationException
InvocationTargetException

public static Class<?> reduceDimensions (Class<?> c)

Reduce dimensions of an array type. Careful, caveat for primitives:

  • non-array => non-array
  • Object[]...[] => Object
  • prim[]...[] => prim[]

Parameters
c a type

public static Class<?> removeDimensions (Class<?> c)

Remove dimensions of an array type.

  • non-array => non-array
  • type[]...[] => type

Parameters
c a type
Returns
  • the dimension-less type

public static void set2 (Field f, Object o, Object value)

Throws
IllegalAccessException
IllegalArgumentException

public static boolean subtypeOf (Class<?> c, Class<?> parent)

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