|
JMMF API pre-release v0.7 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.lang.reflect.AccessibleObject
|
+--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 {
interface A {}
static class B implemnts A {}
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)
throw Throwable
{
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}));
}
}
| Field Summary | |
static java.lang.Class |
NULL_CLASS
|
| Fields inherited from interface java.lang.reflect.Member |
DECLARED, PUBLIC |
| Method Summary | |
static MultiMethod |
create(java.lang.Class clazz,
java.lang.String name,
int argLength)
construct a multi-method by taking all method named name with argLength parameter(s) in class clazz. |
boolean |
equals(java.lang.Object o)
Compares this MultiMethod against the specified
object.
|
java.lang.Class |
getDeclaringClass()
return class that contains all methods of the current multi-method. |
java.lang.Class[] |
getExceptionTypes()
return the exception types of the current method. |
int |
getModifiers()
returns the Java language modifiers for the multi-method represented by this MultiMethod object,
as an integer. |
java.lang.String |
getName()
return the name of the current multi-method. |
java.lang.Class[] |
getParameterTypes()
return the parameter types of the current method. a parameter type is the lowest common subtype of all parameter types of the methods that composed the multi-method. |
java.lang.Class |
getReturnType()
return the return type of the current method. a return type is the lowest common subtype of all return types of the methods that composed the multi-method. |
int |
hashCode()
Returns a hashcode for this MultiMethod.
|
java.lang.Object |
invoke(java.lang.Object target,
java.lang.Object[] args)
call the best 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 best method of the multi-method according to the type of all items if args array on a specified target object. |
java.lang.String |
toString()
return a string representation of the multi-method. |
| Methods inherited from class java.lang.reflect.AccessibleObject |
isAccessible, setAccessible, setAccessible |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.Class NULL_CLASS
| Method Detail |
public boolean equals(java.lang.Object o)
MultiMethod against the specified
object.
Returns true if the objects are the same. Two
MultiMethods are the same if they were declared by the
same class and have the same name and formal
parameter types and return type.equals in class java.lang.Objectpublic int hashCode()
MultiMethod.
The hashcode is computed
as the exclusive-or of the hashcodes for the underlying
method's declaring class name and the method's name.hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.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 best method is called.args - arguments of the multi-method, the types on this
arguments is used to called the best method.NoSuchMethodException, - there is no method that
match the parameter arguments.MultipleMethodsException - there is no method that
match the parameter arguments.java.lang.reflect.InvocationTargetException - if the best method called
raise an exception during its execution, this exception is
wrapped into the InvocationTargetException.java.lang.IllegalAccessException - if best method isn't accessible.Method.invoke(Object,Object[]),
invoke(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 best method is called.args - arguments of the multi-method,types - the best method of the multi-method is
called according to this types.NoSuchMethodException, - there is no method that
match the parameter types.MultipleMethodsException, - there is no method that
match the parameter types.java.lang.reflect.InvocationTargetException - if the best method called
raise an exception during its execution, this exception is
wrapped into the InvocationTargetException.java.lang.IllegalAccessException - if best method isn't accessible.Method.invoke(Object,Object[])public int getModifiers()
MultiMethod object,
as an integer. The Modifier class should
be used to decode the modifiers.getModifiers in interface java.lang.reflect.Memberjava.lang.reflect.Modifierpublic java.lang.String getName()
getName in interface java.lang.reflect.Memberpublic java.lang.Class getDeclaringClass()
getDeclaringClass in interface java.lang.reflect.MemberMethod.getDeclaringClass()public java.lang.Class[] getParameterTypes()
Method.getParameterTypes()public java.lang.Class[] getExceptionTypes()
Method.getExceptionTypes()public java.lang.Class getReturnType()
Method.getReturnType()
public static MultiMethod create(java.lang.Class clazz,
java.lang.String name,
int argLength)
clazz - class which owns the named methods.name - name of the methods.argLenth - 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.7 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||