API文档内容
Invokes the underlying method represented by this Method object, on the specified object with the specified parameters. Individual parameters are automatically unwrapped to match primitive formal parameters, and both primitive and reference parameters are subject to method invocation conversions as necessary.
If the underlying method is static, then the specified obj argument is ignored. It may be null.
If the number of formal parameters required by the underlying method is 0, the supplied args array may be of length 0 or null.
If the underlying method is an instance method, it is invoked using dynamic method lookup as documented in The Java Language Specification, Second Edition, section 15.12.4.4; in particular, overriding based on the runtime type of the target object will occur.
If the underlying method is static, the class that declared the method is initialized if it has not already been initialized.
If the method completes normally, the value it returns is returned to the caller of invoke; if the value has a primitive type, it is first appropriately wrapped in an object. However, if the value has the type of an array of a primitive type, the elements of the array are not wrapped in objects; in other words, an array of primitive type is returned. If the underlying method return type is void, the invocation returns null.
翻译
使用指定的参数在指定的对象上调用此Method对象表示的基础方法。单个参数会自动解包以匹配原始形式参数,并且必要时,原始参数和参考参数都会受方法调用转换的影响。
如果底层方法是静态的,那么指定的obj参数将被忽略。它可能为空。
如果底层方法所需的形式参数数量为0,则所提供的args数组可能长度为0或为空。
如果底层方法是实例方法,则使用动态方法查找来调用该方法,如“Java语言规范第二版”第15.12.4.4节中所述;特别是基于目标对象的运行时类型的覆盖将发生。
如果底层方法是静态的,那么声明该方法的类如果尚未初始化,则会被初始化。
如果方法正常完成,它返回的值将返回给invoke的调用者;如果该值具有基元类型,则首先将其适当包装在一个对象中。但是,如果该值具有基元类型数组的类型,则该数组的元素不会包含在对象中;换句话说,返回一个原始类型的数组。如果基础方法返回类型为void,则调用返回null。