# Class: com.pnfsoftware.jeb.util.reflect.ReflectionHelper

Helper routines using the Java Reflection API.

## Constructor: ReflectionHelper


## Static Method: get2
- parameter: `f`, type: `java.lang.reflect.Field`
- parameter: `o`, type: `java.lang.Object`
- return type: `java.lang.Object`

Description: Retrieve a field value, temporarily making the field accessible if necessary.
parameter: f: field to read
parameter: o: target object, or null for a static field
return: the field value
throws: if the field cannot be accessed
throws: if the target object is invalid

## Static Method: hasNoArgConstructor
- parameter: `c`, type: `java.lang.Class<?>`
- return type: `boolean`

Description: Determine whether a class declares a no\-argument constructor.
parameter: c: class to inspect
return: true if the class declares a no\-argument constructor

## Static Method: instantiateSafe
- parameter: `c`, type: `java.lang.Class<? extends T>`
- return type: `T`

Description: Instantiate a class using its public no\-argument constructor.
parameter: T: object type
parameter: c: class to instantiate
return: the new instance, or null if instantiation failed

## Static Method: invoke2
- parameter: `m`, type: `java.lang.reflect.Method`
- parameter: `o`, type: `java.lang.Object`
- parameter: `args`, type: `java.lang.Object[]`
- return type: `java.lang.Object`

Description: Invoke a method, temporarily making it accessible if necessary.
parameter: m: method to invoke
parameter: o: target object, or null for a static method
parameter: args: invocation arguments
return: the invocation result
throws: if the method cannot be accessed
throws: if the target object or arguments are invalid
throws: if the method throws an exception

## Static Method: isInstance
- parameter: `o`, type: `java.lang.Object`
- parameter: `classObjects`, type: `java.util.Collection<java.lang.Class<? extends T>>`
- return type: `boolean`

Description: A multi\-element variant of [Class#isInstance(Object)](Class#isInstance(Object)).
parameter: o: the object to be tested
parameter: classObjects: a collection of `Class` objects
return: true if o can be cast to one of the provided class objects

## Static Method: isInstance
- parameter: `o`, type: `java.lang.Object`
- parameter: `classObjects`, type: `java.lang.Class<?>[]`
- return type: `boolean`

Description: A multi\-element variant of [Class#isInstance(Object)](Class#isInstance(Object)).
parameter: o: the object to be tested
parameter: classObjects: a collection of `Class` objects
return: true if o can be cast to one of the provided class objects

## Static Method: newInstance2
- parameter: `constructor`, type: `java.lang.reflect.Constructor<?>`
- return type: `java.lang.Object`

Description: Instantiate an object using a no\-argument constructor, temporarily making it accessible if necessary.
parameter: constructor: constructor to invoke
return: the new instance
throws: if the declaring class cannot be instantiated
throws: if the constructor cannot be accessed
throws: if the constructor invocation arguments are invalid
throws: if the constructor throws an exception

## Static Method: openAllModules
- parameter: `clzInUnnamedModule`, type: `java.lang.Class<?>`

Description: Grant reflection access to non\-public members of Java named modules to an unnamed module. Required for JDK 17\+, since `--illegal-access=` is no longer an option. 

 Implementation note: this code relies on `Module.implAddExportsOrOpens()`; therefore access to `java.lang` must have been granted to the JVM \(e.g. via `--add-opens java.base/java.lang=ALL-UNNAMED` on the command line\).
parameter: clzInUnnamedModule: a class in the unnamed module
throws: raised if any reflection error or illegal access error happens

## Static Method: reduceDimensions
- parameter: `c`, type: `java.lang.Class<?>`
- return type: `java.lang.Class<?>`

Description: Reduce dimensions of an array type. Careful, caveat for primitives: 
 
- non\-array =\> non\-array
-  
- Object\[\]...\[\] =\> Object
-  
- prim\[\]...\[\] =\> prim\[\]
-
parameter: c: a type
return: the reduced type

## Static Method: removeDimensions
- parameter: `c`, type: `java.lang.Class<?>`
- return type: `java.lang.Class<?>`

Description: Remove dimensions of an array type. 
 
- non\-array =\> non\-array
-  
- type\[\]...\[\] =\> type
-
parameter: c: a type
return: the dimension\-less type

## Static Method: set2
- parameter: `f`, type: `java.lang.reflect.Field`
- parameter: `o`, type: `java.lang.Object`
- parameter: `value`, type: `java.lang.Object`

Description: Set a field value, temporarily making the field accessible if necessary.
parameter: f: field to set
parameter: o: target object, or null for a static field
parameter: value: value to set
throws: if the field cannot be accessed
throws: if the target object or value is invalid

## Static Method: subtypeOf
- parameter: `c`, type: `java.lang.Class<?>`
- parameter: `parent`, type: `java.lang.Class<?>`
- return type: `boolean`

Description: Determine if a type is a descendant of the provided ancestor.
parameter: c: a type \(class or interface\)
parameter: parent: a candidate ancestor type \(class or interface\)
return: true or false

