clean up Array.get(), Array.set(), and Method.invoke() implementations

This commit is contained in:
Joel Dice
2007-08-18 11:53:30 -06:00
parent d169e4eadf
commit aa5e751e69
6 changed files with 170 additions and 157 deletions

View File

@ -87,6 +87,27 @@ public class Method<T> extends AccessibleObject implements Member {
return types;
}
public native Object invoke(Object instance, Object ... arguments)
public Object invoke(Object instance, Object ... arguments)
throws InvocationTargetException, IllegalAccessException
{
if ((flags & Modifier.STATIC) != 0) {
if (arguments.length == parameterCount) {
return invoke(this, instance, arguments);
} else {
throw new ArrayIndexOutOfBoundsException();
}
} else if (class_.isInstance(instance)) {
if (arguments.length == parameterCount - 1) {
return invoke(this, instance, arguments);
} else {
throw new ArrayIndexOutOfBoundsException();
}
} else {
throw new IllegalArgumentException();
}
}
public static native Object invoke(Method method, Object instance,
Object ... arguments)
throws InvocationTargetException, IllegalAccessException;
}