In terms of effect, after Class 类的 getMethod 方法,这两种参数没有区别。 我们可以查看 getMethod 的源码,getMethod is called layer by layer, the following method will be used:
In this method, you can see that there is a arrayContentsEq method used to match the parameters of the method:
It can be found that for the case where parameterTypes is null, and for the case where null 的情况,和对于 parameterTypes 为空数组(length == 0)的情况,效果是一样的 —— 假设此时我们要获取的方法 m 的参数为空,那么该方法的 m.getParameterTypes() 返回的数组(a2)的长度即为 0,我们可以发现 a1 == null 或者 a1.length == 0 的时候,arrayContentsEq 方法返回的都是 trueparameterTypes
is an empty array (length == 0), the effect is the same - assuming that we want to obtain at this time If the parameters of method m are empty, then the length of the array (a2) returned by m.getParameterTypes() of this method is 0. We can find that a1 == null or When a1.length == 0, the 🎜 method returns true (that is, the match is successful). 🎜
In terms of effect, after
Class
类的getMethod
方法,这两种参数没有区别。我们可以查看
getMethod
的源码,getMethod
is called layer by layer, the following method will be used:In this method, you can see that there is a
arrayContentsEq
method used to match the parameters of the method:It can be found that for the case where parameterTypes is
is an empty array (length == 0), the effect is the same - assuming that we want to obtain at this time If the parameters of method m are empty, then the length of the array (a2) returned bynull
, and for the case wherenull
的情况,和对于 parameterTypes 为空数组(length == 0)的情况,效果是一样的 —— 假设此时我们要获取的方法 m 的参数为空,那么该方法的m.getParameterTypes()
返回的数组(a2)的长度即为 0,我们可以发现a1 == null
或者a1.length == 0
的时候,arrayContentsEq
方法返回的都是true
parameterTypesm.getParameterTypes()
of this method is 0. We can find thata1 == null
or Whena1.length == 0
, the 🎜 method returnstrue
(that is, the match is successful). 🎜If a method has no parameters, there is actually no difference between the two situations.
Track
getMethod(String name, Class<?>... parameterTypes)
的源码,可以发现如下代码,其中a1为传入的parameterTypes
,a2
为根据参数name
找到的Method
实例调用的method.getParameterTypes()
。程序根据比较a1
和a2
来返回正确的Method
.