javautils.fun
Class Function

java.lang.Object
  |
  +--javautils.fun.Function
Direct Known Subclasses:
ObjectToBoolean, ObjectToObject, ObjectToObjectToBoolean, ObjectToObjectToObject, ObjectToObjectToVoid, ObjectToVoid, VoidToObject, VoidToVoid

public class Function
extends java.lang.Object

An arbitrary function or procedure.

The intention of this class is to help emulate anonymous functions, also known as lambda-expressions, using anonymous inner classes. The user derives from this class and defines a public with()-method. The with()-method can then be accessed using the services of this base class.

It usually makes sense to derive a more specific abstract function class from this class, so that the function signature can be type checked more thoroughly and that calling the function becomes more convenient and efficient.

Among many other things, [Abelson1995] introduces functional programming and lambda-expressions in the context of Scheme. Anonymous functions are also related to the Strategy-design pattern described in [Gamma1995].


Constructor Summary
protected Function()
          A new function bound to this object and the with()-method defined by the derived class.
  Function(java.lang.Object self, java.lang.reflect.Method method)
          A new function bound to the specified object and method.
  Function(java.lang.Object self, java.lang.String methodName)
          A new function bound to the specified object and named public method.
  Function(java.lang.Object self, java.lang.String methodName, java.lang.Class argType)
          A new function bound to the specified object and named public method.
  Function(java.lang.Object self, java.lang.String methodName, java.lang.Class[] argTypes)
          A new function bound to the specified object and named public method.
 
Method Summary
 java.lang.reflect.Method getMethod()
          The bound method.
 java.lang.Object getSelf()
          The bound object.
 java.lang.Object invoke(java.lang.Object[] args)
          Invokes the bound method on the bound object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Function

protected Function()

A new function bound to this object and the with()-method defined by the derived class.


Function

public Function(java.lang.Object self,
                java.lang.String methodName)

A new function bound to the specified object and named public method.


Function

public Function(java.lang.Object self,
                java.lang.String methodName,
                java.lang.Class argType)

A new function bound to the specified object and named public method.


Function

public Function(java.lang.Object self,
                java.lang.String methodName,
                java.lang.Class[] argTypes)

A new function bound to the specified object and named public method.


Function

public Function(java.lang.Object self,
                java.lang.reflect.Method method)

A new function bound to the specified object and method.

Method Detail

invoke

public java.lang.Object invoke(java.lang.Object[] args)

Invokes the bound method on the bound object.

Any checked exceptions thrown by the bound method will be thrown wrapped inside RuntimeException-exceptions.


getMethod

public final java.lang.reflect.Method getMethod()

The bound method.


getSelf

public final java.lang.Object getSelf()

The bound object.