How to get string name of a method in java?

前端 未结 7 702
梦谈多话
梦谈多话 2020-11-29 06:10

How can I find out through reflection what is the string name of the method?

For example given:

class Car{
   public void getFoo(){
   }
}

7条回答
  •  日久生厌
    2020-11-29 06:24

    Wait, since you already know the method name, can't you just type it as a string?

    Instead of (pseudo) Class.methodName.toString(), just use "methodName".

    Otherwise you can use Class#getDeclaredMethods() to get all the methods in a class

提交回复
热议问题