Getting a method object without calling a method by name

Is there a way to get a method object without using the method name to capture it?

For example, I have a class:

class Car {

    public String drive();
    public String giveUp();
    public String fillUp();
}

I would like to create Map<String, Method>methods (aka: ("move", drive ()) ("name", giveUp ()), ....).

I cannot get the method object through the name due to the use of obfuscation. Is there a way to capture a method name without having to bind this?

I assume another way to ask the question is:

For the class you have getClass (), is there an equivalent for the methods? I am looking for something related to giveUp.Method parameters.

+3
source share
2 answers

Java , Car.giveUp.method(), " ", .

, obfuscator , , , , .

  • , , .

  • ,

    @MappedMethod("move")
    public String drive();
    

    @MappedMethod String. , , .

+4

Reflection .

Class<Car> clazz = Car.class;
Method[] methods = clazz.getDeclaredMethods();

:

for(Method method: methods)
    map.put( method.getName(), method);
+3

All Articles