|
|||||||||
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.property.Invoke<R>
public class Invoke<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 © 2009 David A. Hall
Nested Class Summary | |
---|---|
static interface |
Invoke.Visitor
Interface for classes that may interpret a InvokeMethod function. |
Constructor Summary | |
---|---|
Invoke(java.lang.Class<?> objClass,
java.lang.reflect.Method method)
Builds a InvokeMethod for a given method |
|
Invoke(java.lang.Class<?> 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. |
|
Invoke(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)
A non-typesafe evaluation method for function objects. |
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<?> |
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.Functor |
---|
bind0th, bindNth, composeNth, composeNth, generateNth |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Invoke(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 Invoke(java.lang.Class<?> 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 Invoke(java.lang.Class<?> 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<?> 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 eval(java.lang.Object... args)
Functor
eval
in class Functor<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 |