java.lang.Object | |
↳ | org.apache.commons.beanutils.MethodUtils |
Utility reflection methods focussed on methods in general rather than properties in particular.
There is an issue when invoking public methods contained in a default access superclass.
Reflection locates these methods fine and correctly assigns them as public.
However, an IllegalAccessException
is thrown if the method is invoked.
MethodUtils
contains a workaround for this situation.
It will attempt to call setAccessible
on this method.
If this call succeeds, then the method can be invoked as normal.
This call will only succeed when the application has sufficient security privilages.
If this call fails then a warning will be logged and the method may fail.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clear the method cache.
| |||||||||||
Return an accessible method (that is, one that can be invoked via reflection) with given name and parameters. | |||||||||||
Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. | |||||||||||
Return an accessible method (that is, one that can be invoked via reflection) with given name and a single parameter. | |||||||||||
Return an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. | |||||||||||
Find an accessible method that matches the given name and has compatible parameters. | |||||||||||
Gets the class for the primitive type corresponding to the primitive wrapper class given.
| |||||||||||
Gets the wrapper object class for the given primitive type class.
| |||||||||||
Invoke a method whose parameter type matches exactly the object type. | |||||||||||
Invoke a method whose parameter types match exactly the object types. | |||||||||||
Invoke a method whose parameter types match exactly the parameter types given. | |||||||||||
Invoke a static method whose parameter types match exactly the object types. | |||||||||||
Invoke a static method whose parameter type matches exactly the object type. | |||||||||||
Invoke a static method whose parameter types match exactly the parameter types given. | |||||||||||
Invoke a named method whose parameter type matches the object type. | |||||||||||
Invoke a named method whose parameter type matches the object type. | |||||||||||
Invoke a named method whose parameter type matches the object type. | |||||||||||
Invoke a named static method whose parameter type matches the object type. | |||||||||||
Invoke a named static method whose parameter type matches the object type. | |||||||||||
Invoke a named static method whose parameter type matches the object type. | |||||||||||
Determine whether a type can be used as a parameter in a method invocation. | |||||||||||
Set whether methods should be cached for greater performance or not,
default is
true . | |||||||||||
Find a non primitive representation for given primitive class.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Clear the method cache.
Return an accessible method (that is, one that can be invoked via
reflection) with given name and parameters. If no such method
can be found, return null
.
This is just a convenient wrapper for
getAccessibleMethod(Method)
.
clazz | get method from this class |
---|---|
methodName | get method with this name |
parameterTypes | with these parameters types |
Return an accessible method (that is, one that can be invoked via
reflection) that implements the specified Method. If no such method
can be found, return null
.
clazz | The class of the object |
---|---|
method | The method that we wish to call |
Return an accessible method (that is, one that can be invoked via
reflection) with given name and a single parameter. If no such method
can be found, return null
.
Basically, a convenience wrapper that constructs a Class
array for you.
clazz | get method from this class |
---|---|
methodName | get method with this name |
parameterType | taking this type of parameter |
Return an accessible method (that is, one that can be invoked via
reflection) that implements the specified Method. If no such method
can be found, return null
.
method | The method that we wish to call |
---|
Find an accessible method that matches the given name and has compatible parameters. Compatible parameters mean that every method parameter is assignable from the given parameters. In other words, it finds a method with the given name that will take the parameters given.
This method is slightly undeterminstic since it loops through methods names and return the first matching method.
This method is used by
invokeMethod(Object, String, Object[], Class[])
.
This method can match primitive parameter by passing in wrapper classes.
For example, a Boolean
will match a primitive boolean
parameter.
clazz | find method in this class |
---|---|
methodName | find method with this name |
parameterTypes | find method with compatible parameters |
Gets the class for the primitive type corresponding to the primitive wrapper class given.
For example, an instance of Boolean.class
returns a boolean.class
.
wrapperType | the |
---|
Gets the wrapper object class for the given primitive type class.
For example, passing boolean.class
returns Boolean.class
primitiveType | the primitive type class for which a match is to be found |
---|
Invoke a method whose parameter type matches exactly the object type.
This is a convenient wrapper for
invokeExactMethod(Object, String, Object[])
.
object | invoke method on this object |
---|---|
methodName | get method with this name |
arg | use this argument |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a method whose parameter types match exactly the object types.
This uses reflection to invoke the method obtained from a call to
getAccessibleMethod()
.
object | invoke method on this object |
---|---|
methodName | get method with this name |
args | use these arguments - treat null as empty array |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a method whose parameter types match exactly the parameter types given.
This uses reflection to invoke the method obtained from a call to
getAccessibleMethod()
.
object | invoke method on this object |
---|---|
methodName | get method with this name |
args | use these arguments - treat null as empty array |
parameterTypes | match these parameters - treat null as empty array |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a static method whose parameter types match exactly the object types.
This uses reflection to invoke the method obtained from a call to
getAccessibleMethod(Class, String, Class[])
.
objectClass | invoke static method on this class |
---|---|
methodName | get method with this name |
args | use these arguments - treat null as empty array |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a static method whose parameter type matches exactly the object type.
This is a convenient wrapper for
invokeExactStaticMethod(Class, String, Object[])
.
objectClass | invoke static method on this class |
---|---|
methodName | get method with this name |
arg | use this argument |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a static method whose parameter types match exactly the parameter types given.
This uses reflection to invoke the method obtained from a call to
getAccessibleMethod(Class, String, Class[])
.
objectClass | invoke static method on this class |
---|---|
methodName | get method with this name |
args | use these arguments - treat null as empty array |
parameterTypes | match these parameters - treat null as empty array |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a named method whose parameter type matches the object type.
The behaviour of this method is less deterministic
than invokeExactMethod(Object, String, Object[], Class[])
.
It loops through all methods with names that match
and then executes the first it finds with compatable parameters.
This method supports calls to methods taking primitive parameters
via passing in wrapping classes. So, for example, a Boolean
class
would match a boolean
primitive.
object | invoke method on this object |
---|---|
methodName | get method with this name |
args | use these arguments - treat null as empty array |
parameterTypes | match these parameters - treat null as empty array |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a named method whose parameter type matches the object type.
The behaviour of this method is less deterministic
than invokeExactMethod(Object, String, Object[])
.
It loops through all methods with names that match
and then executes the first it finds with compatable parameters.
This method supports calls to methods taking primitive parameters
via passing in wrapping classes. So, for example, a Boolean
class
would match a boolean
primitive.
This is a convenient wrapper for
invokeMethod(Object, String, Object[], Class[])
.
object | invoke method on this object |
---|---|
methodName | get method with this name |
args | use these arguments - treat null as empty array |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a named method whose parameter type matches the object type.
The behaviour of this method is less deterministic
than invokeExactMethod()
.
It loops through all methods with names that match
and then executes the first it finds with compatable parameters.
This method supports calls to methods taking primitive parameters
via passing in wrapping classes. So, for example, a Boolean
class
would match a boolean
primitive.
This is a convenient wrapper for
invokeMethod(Object, String, Object[])
.
object | invoke method on this object |
---|---|
methodName | get method with this name |
arg | use this argument |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a named static method whose parameter type matches the object type.
The behaviour of this method is less deterministic
than invokeExactMethod(Object, String, Object[], Class[])
.
It loops through all methods with names that match
and then executes the first it finds with compatable parameters.
This method supports calls to methods taking primitive parameters
via passing in wrapping classes. So, for example, a Boolean
class
would match a boolean
primitive.
This is a convenient wrapper for
invokeStaticMethod(Class, String, Object[])
.
objectClass | invoke static method on this class |
---|---|
methodName | get method with this name |
arg | use this argument |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a named static method whose parameter type matches the object type.
The behaviour of this method is less deterministic
than invokeExactMethod(Object, String, Object[])
.
It loops through all methods with names that match
and then executes the first it finds with compatable parameters.
This method supports calls to methods taking primitive parameters
via passing in wrapping classes. So, for example, a Boolean
class
would match a boolean
primitive.
This is a convenient wrapper for
invokeStaticMethod(Class, String, Object[], Class[])
.
objectClass | invoke static method on this class |
---|---|
methodName | get method with this name |
args | use these arguments - treat null as empty array |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Invoke a named static method whose parameter type matches the object type.
The behaviour of this method is less deterministic
than invokeExactStaticMethod(Class, String, Object[], Class[])
.
It loops through all methods with names that match
and then executes the first it finds with compatable parameters.
This method supports calls to methods taking primitive parameters
via passing in wrapping classes. So, for example, a Boolean
class
would match a boolean
primitive.
objectClass | invoke static method on this class |
---|---|
methodName | get method with this name |
args | use these arguments - treat null as empty array |
parameterTypes | match these parameters - treat null as empty array |
NoSuchMethodException | if there is no such accessible method |
---|---|
InvocationTargetException | wraps an exception thrown by the method invoked |
IllegalAccessException | if the requested method is not accessible via reflection |
Determine whether a type can be used as a parameter in a method invocation. This method handles primitive conversions correctly.
In order words, it will match a Boolean
to a boolean
,
a Long
to a long
,
a Float
to a float
,
a Integer
to a int
,
and a Double
to a double
.
Now logic widening matches are allowed.
For example, a Long
will not match a int
.
parameterType | the type of parameter accepted by the method |
---|---|
parameterization | the type of parameter being tested |
Set whether methods should be cached for greater performance or not,
default is true
.
cacheMethods | true if methods should be
cached for greater performance, otherwise false |
---|
Find a non primitive representation for given primitive class.
clazz | the class to find a representation for, not null |
---|