@@ -1120,13 +1120,7 @@ public static Method getMethod(Class<?> clazz, String methodName, @Nullable Clas
1120
1120
}
1121
1121
}
1122
1122
else {
1123
- Set <Method > candidates = new HashSet <>(1 );
1124
- Method [] methods = clazz .getMethods ();
1125
- for (Method method : methods ) {
1126
- if (methodName .equals (method .getName ())) {
1127
- candidates .add (method );
1128
- }
1129
- }
1123
+ Set <Method > candidates = findMethodCandidatesByName (clazz , methodName );
1130
1124
if (candidates .size () == 1 ) {
1131
1125
return candidates .iterator ().next ();
1132
1126
}
@@ -1165,13 +1159,7 @@ public static Method getMethodIfAvailable(Class<?> clazz, String methodName, @Nu
1165
1159
}
1166
1160
}
1167
1161
else {
1168
- Set <Method > candidates = new HashSet <>(1 );
1169
- Method [] methods = clazz .getMethods ();
1170
- for (Method method : methods ) {
1171
- if (methodName .equals (method .getName ())) {
1172
- candidates .add (method );
1173
- }
1174
- }
1162
+ Set <Method > candidates = findMethodCandidatesByName (clazz , methodName );
1175
1163
if (candidates .size () == 1 ) {
1176
1164
return candidates .iterator ().next ();
1177
1165
}
@@ -1362,4 +1350,14 @@ public static Method getStaticMethod(Class<?> clazz, String methodName, Class<?>
1362
1350
}
1363
1351
}
1364
1352
1353
+ private static Set <Method > findMethodCandidatesByName (Class <?> clazz , String methodName ) {
1354
+ Set <Method > candidates = new HashSet <>(1 );
1355
+ Method [] methods = clazz .getMethods ();
1356
+ for (Method method : methods ) {
1357
+ if (methodName .equals (method .getName ())) {
1358
+ candidates .add (method );
1359
+ }
1360
+ }
1361
+ return candidates ;
1362
+ }
1365
1363
}
0 commit comments