1

There is similar question regarding this but in the answers the parameter types are used.

My question is that having a class what should be done to find out whether the method returned using reflection is overloaded or not?

Possible ways can be: 1) Looping to find the same method again

    List<Method> overloaded = new ArrayList<Method>();
    Method[] declaredMethods = A.class.getDeclaredMethods();

    for(int i = 0; i < declaredMethods.length; i++){
        for(int j = (i + 1); j < declaredMethods.length; j++){
            if(declaredMethods[j].getName().equals(declaredMethods[i].getName())){
                overloaded.add(declaredMethods[i]);
            }
        }
    }

    System.out.println(overloaded);

Is there some way to find out overloaded methods which has a better algorithmic complexity than this? Does some library provide the same functionality?

Community
  • 1
  • 1
Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120

1 Answers1

2

You could use a Set. if the add() operation returns false the method name is already in the set.
Java Reflection has no method to determine whether a method is overloaded.

AlexWien
  • 28,470
  • 6
  • 53
  • 83