code: private static Method getMethodWithMostSpecificParameterTypes(Method firstMethodCandidate, Method secondMethodCandidate) {
          Class<?>[] firstMethodCandidateParameterTypes = firstMethodCandidate.getParameterTypes();
          Class<?>[] secondMethodCandidateParameterTypes = secondMethodCandidate.getParameterTypes();
  
          Method bestMatch = null;
          for (int i = 0; i < firstMethodCandidateParameterTypes.length; i++) {
              Class<?> candidateType1 = toBoxedIfPrimitive(firstMethodCandidateParameterTypes[i]);
              Class<?> candidateType2 = toBoxedIfPrimitive(secondMethodCandidateParameterTypes[i]);
  
              if (!candidateType1.equals(candidateType2)) {
                  Method potentialMatch = null;
                  if (candidateType1.isAssignableFrom(candidateType2)) {
                      potentialMatch = secondMethodCandidate;
                  } else if (candidateType2.isAssignableFrom(candidateType1)) {
                      potentialMatch = firstMethodCandidate;
                  }
  
                  if (potentialMatch != null) {
                      if (bestMatch != null && !potentialMatch.equals(bestMatch)) {
                          /*
                           * We cannot determine which method is the most specific because one parameter of the first candidate
                           * was more specific and another parameter of the second candidate was more specific.
                           */
                          return null;
                      } else {
                          bestMatch = potentialMatch;
                      }
                  }
              }
          }
  
          return bestMatch;
      }
docs: Find the method whose parameter types most closely matches the {@code types}.
  
  @param firstMethodCandidate  The first method candidate
  @param secondMethodCandidate The second method candidate
  @return The method that most closely matches the provided types or {@code null} if no method match.