How can I find out through reflection what is the string name of the method?
For example given:
class Car{
public void getFoo(){
}
}
I want to get the string “getFoo”, something like the following:
Car.getFoo.toString() == "getFoo" // TRUE
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since methods aren’t objects themselves, they don’t have direct properties (like you would expect with first-class functions in languages like JavaScript).
The closest you can do is call
Car.class.getMethods()Car.classis aClassobject which you can use to invoke any of the reflection methods.However, as far as I know, a method is not able to identify itself.