public class PrivateAccessor
extends java.lang.Object
int.class>,
double.class>, short.class>, long.class>,
float.class> and char.class> for primitive types.
Example: To set the value of an object obj> to 100 via the method
setValue()>:
PrivateAccessor.invoke( obj, "setValue", new Class[]{int.class}, new Object[]{new Integer( 100 )} );
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
getField(java.lang.Class cls,
java.lang.String name)
Returns the value of the field on the specified class.
|
static java.lang.Object |
getField(java.lang.Object object,
java.lang.String name)
Returns the value of the field on the specified object.
|
static java.lang.Object |
invoke(java.lang.Class cls,
java.lang.String name,
java.lang.Class[] parameterTypes,
java.lang.Object[] args)
Invokes the method represented by the name value on the specified class
with the specified parameters.
|
static java.lang.Object |
invoke(java.lang.Object object,
java.lang.String name,
java.lang.Class[] parameterTypes,
java.lang.Object[] args)
Invokes the method represented by the name value on the specified object
with the specified parameters.
|
static void |
setField(java.lang.Class cls,
java.lang.String name,
java.lang.Object value)
Sets the field represented by the name value on the specified class
argument to the specified new value.
|
static void |
setField(java.lang.Object object,
java.lang.String name,
java.lang.Object value)
Sets the field represented by the name value on the specified object
argument to the specified new value.
|
public static java.lang.Object getField(java.lang.Object object, java.lang.String name) throws java.lang.NoSuchFieldException
String
specifying the simple name of the
desired field.The object is first searched for any matching field. If no matching field is found, the superclasses are recursively searched.
java.lang.NoSuchFieldException
- if a field with the specified name is
not found.public static java.lang.Object getField(java.lang.Class cls, java.lang.String name) throws java.lang.NoSuchFieldException
String
specifying the simple name of the
desired field.The class is first searched for any matching field. If no matching field is found, the superclasses are recursively searched.
java.lang.NoSuchFieldException
- if a field with the specified name is
not found.public static void setField(java.lang.Object object, java.lang.String name, java.lang.Object value) throws java.lang.NoSuchFieldException
The object is first searched for any matching field. If no matching field is found, the superclasses are recursively searched.
java.lang.NoSuchFieldException
- if a field with the specified name is
not found.public static void setField(java.lang.Class cls, java.lang.String name, java.lang.Object value) throws java.lang.NoSuchFieldException
The class is first searched for any matching field. If no matching field is found, the superclasses are recursively searched.
java.lang.NoSuchFieldException
- if a field with the specified name is
not found.public static java.lang.Object invoke(java.lang.Object object, java.lang.String name, java.lang.Class[] parameterTypes, java.lang.Object[] args) throws java.lang.Throwable
The object is first searched for any matching method. If no matching method is found, the superclasses are recursively searched.
java.lang.NoSuchMethodException
- if a matching method is not found or
if the name is "java.lang.Throwable
public static java.lang.Object invoke(java.lang.Class cls, java.lang.String name, java.lang.Class[] parameterTypes, java.lang.Object[] args) throws java.lang.Throwable
The class is first searched for any matching method. If no matching class is found, the superclasses are recursively searched.
java.lang.NoSuchMethodException
- if a matching method is not found or
if the name is "java.lang.Throwable
Copyright © ${project.year} ${project.holder}. All Rights Reserved.