I'm looking for a convenient workaround for getting the Method object from a method. The idea:
Method fooMethod = getMethod( new MyObject().foo() ) // returns method "foo" in MyObject
The obvious way is to use the name of the method as a string:
Method fooMethod = MyObject.class.getMethod("foo")
but I want to avoid this because if I rename foo() that code will stop working or I have rename the string in all the places where it is used.
The use case is that I want to use something similar to ProperyChangeListeners however those rely on the method name as string. I'd like to use the actual method (safely) and not rely on strings.
What could I use to get the method in a rename safe way?
UPDATE: I'd like to find a pure java solution that does not rely on IDE features