|
JMMF API pre-release v0.8 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--fr.umlv.jmmf.reflect.MultiMethod
The multi-method object.
This class support the 1.2 security model.
The current implementation of the multi-method mecanism
desactivate default Java language access control checks.
see AccessibleObject.
The method create permit to
create a multi-method object.
import fr.umlv.jmmf.reflect.*;
public class Test {
public interface A {}
public static class B implements A {}
public static class C implements A {
int value;
}
static public String toString(B b) {
return b.toString();
}
static public String toString(C c) {
return String.valueOf(c.value);
}
public static void main(String[] args)
throws Exception
{
MultiMethod mm=MultiMethod.create(Test.class,"toString",1);
A a=new B();
System.out.println(mm.invoke(null,new Object[]{a}));
a=new C();
System.out.println(mm.invoke(null,new Object[]{a}));
}
}
| Method Summary | |
static MultiMethod |
create(java.lang.Class clazz,
java.lang.String name,
int parameterLength)
construct a multi-method by taking all method named name with parameterLength parameter(s) in class clazz. |
java.lang.Class |
getDeclaringClass()
return the class on which the multi-method is declared. |
java.lang.reflect.Method |
getMethod(java.lang.Class target,
java.lang.Class[] types)
return the most specific method of the multi-method according to the type of all items if args array on a specified target object. |
java.lang.String |
getName()
return the name of the current multi-method. |
int |
getParameterLength()
return the number of parameters of the current multi-method. |
java.lang.Object |
invoke(java.lang.Object target,
java.lang.Object[] args)
call the most specific method of the multi-method according to the type of all items if args array on a specified target object. |
java.lang.Object |
invoke(java.lang.Object target,
java.lang.Object[] args,
java.lang.Class[] types)
call the most specific method of the multi-method according to the type of all items if args array on a specified target object. |
boolean |
isOnlyPublic()
return true is the multi-method is constructed using the onlyPublic flag. |
java.lang.String |
toString()
return a string representation of the multi-method. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
public java.lang.reflect.Method getMethod(java.lang.Class target,
java.lang.Class[] types)
throws java.lang.NoSuchMethodException,
MultipleMethodsException
target - class in which the most specific method is declared.types - parameter types used to find the most specific method.NoSuchMethodException, - there is no method that
match the parameter arguments.MultipleMethodsException - there are multiple methods that
match the parameter arguments.java.lang.Class#getMethod(Class[]),
#invoke(Object, Object[], Object[])
public java.lang.Object invoke(java.lang.Object target,
java.lang.Object[] args)
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.NoSuchMethodException,
MultipleMethodsException
target - object on which the most specific method is called.args - arguments of the multi-method, the types on this
arguments is used to called the most specific method.NoSuchMethodException, - there is no method that
match the parameter arguments.MultipleMethodsException - there are multiple methods that
match the parameter arguments.java.lang.reflect.InvocationTargetException - if the most specific
method called raise an exception during its execution,
this exception is wrapped into the InvocationTargetException.java.lang.IllegalArgumentException - if the target class isn't
a subtype of the declaring class.java.lang.IllegalAccessException - if most specific method
isn't accessible.Method.invoke(Object,Object[]),
#invoke(Object, Object[], Object[])
public java.lang.Object invoke(java.lang.Object target,
java.lang.Object[] args,
java.lang.Class[] types)
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.NoSuchMethodException,
MultipleMethodsException
target - object on which the most specific method is called.args - arguments of the multi-method,types - the most specific method of the multi-method is
called according to this types.NoSuchMethodException, - there is no method that
match the parameter types.MultipleMethodsException - there are multiple methods
that match the parameter arguments.java.lang.reflect.InvocationTargetException - if the most specific
method called raise an exception during its execution,
this exception is wrapped into the InvocationTargetException.java.lang.IllegalArgumentException - if the target class isn't
a subtype of the declaring class.java.lang.IllegalAccessException - if most specific method isn't
accessible.Method.invoke(Object,Object[])public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isOnlyPublic()
MultiFactory.create(Class,String,int,boolean)public int getParameterLength()
public java.lang.String getName()
public java.lang.Class getDeclaringClass()
public static MultiMethod create(java.lang.Class clazz,
java.lang.String name,
int parameterLength)
clazz - class which owns the named methods.name - name of the methods.parameterLength - number of parameters.java.lang.IllegalArgumentException - if the class
clazz contains no method named name or all methods
found don't have the same number of parameters.MultiFactory,
MultiFactory.create(Class,String,int)
|
JMMF API pre-release v0.8 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||