|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.jga.fn.Functor<R> net.sf.jga.fn.BinaryFunctor<T,java.lang.Object[],R> net.sf.jga.fn.property.InvokeMethod<T,R>
public class InvokeMethod<T,R>
Functor that invokes a method described at construction and returns the result or null if the result is void. The arguments must be passed to the functor in an array, and the values must be assignable to the corresponding classes given at construction.
Note that declaring the return type incorrectly can result in ClassCastExceptions being thrown when the functor is invoked: the compiler cannot check the return type of a reflectively loaded method, unless we add more arguments to the constructor.
Copyright © 2003-2005 David A. Hall
Nested Class Summary | |
---|---|
static interface |
InvokeMethod.Visitor
Interface for classes that may interpret a InvokeMethod function. |
Constructor Summary | |
---|---|
InvokeMethod(java.lang.Class<T> objClass,
java.lang.reflect.Method method)
Builds a InvokeMethod for a given method |
|
InvokeMethod(java.lang.Class<T> objClass,
java.lang.String methName,
java.lang.Class<?>... argtypes)
Builds a InvokeMethod for the given method, using the given class array to find the desired method. |
|
InvokeMethod(java.lang.Class<T> objClass,
java.lang.String methName,
java.lang.Class<?> argtype)
Builds an InvokeMethod for a given method, using the given class to find the desired method. |
|
InvokeMethod(java.lang.reflect.Method method)
Builds an InvokeMethod functor for the given method. |
Method Summary | |
---|---|
void |
accept(Visitor v)
Calls the Visitor's visit(InvokeMethod) method, if it
implements the nested Visitor interface. |
R |
eval(java.lang.Object... args)
Executes the function and returns the result. |
R |
fn(T obj,
java.lang.Object[] args)
Executes the function and returns the result. |
java.lang.reflect.Method |
getMethod()
Lazy loads the method |
java.lang.String |
getMethodName()
Returns the name of the method that this functor invokes. |
java.lang.Class<T> |
getObjectType()
Returns the class which supplied the method is invoked. |
java.lang.Class<R> |
getReturnType()
Returns the type of the method |
java.lang.String |
toString()
|
Methods inherited from class net.sf.jga.fn.BinaryFunctor |
---|
bind, bind0th, bind1st, bind2nd, bindNth, compose, compose, composeNth, distribute, generate, generate1st, generate2nd, generateNth |
Methods inherited from class net.sf.jga.fn.Functor |
---|
composeNth |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public InvokeMethod(java.lang.reflect.Method method)
NOTE: this constructor has lower type-safety guarantee than the other constructors, in that the compiler cannot check that the method's declaring class is T. When a functor built by this constructor is evaluated, it will throw IllegalArgumentException if given an incompatible argument.
java.lang.IllegalArgumentException
- if the method is null or if it takes argumentspublic InvokeMethod(java.lang.Class<T> objClass, java.lang.reflect.Method method)
java.lang.IllegalArgumentException
- if the method or class is null; or if the method is not supplied
by the given class;public InvokeMethod(java.lang.Class<T> objClass, java.lang.String methName, java.lang.Class<?> argtype)
java.lang.IllegalArgumentException
- if class, method name, or argument type array is null;
or if the class does not supply the described method.public InvokeMethod(java.lang.Class<T> objClass, java.lang.String methName, java.lang.Class<?>... argtypes)
java.lang.IllegalArgumentException
- if class, method name, or argument type array is null;
or if the class does not supply the described method.Method Detail |
---|
public java.lang.Class<T> getObjectType()
public java.lang.String getMethodName()
public java.lang.Class<R> getReturnType()
public java.lang.reflect.Method getMethod() throws java.lang.NoSuchMethodException
java.lang.NoSuchMethodException
public R fn(T obj, java.lang.Object[] args)
BinaryFunctor
fn
in class BinaryFunctor<T,java.lang.Object[],R>
public R eval(java.lang.Object... args)
BinaryFunctor
eval
in class BinaryFunctor<T,java.lang.Object[],R>
public void accept(Visitor v)
visit(InvokeMethod)
method, if it
implements the nested Visitor interface.
accept
in interface Visitable
accept
in class Functor<R>
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |