0

I would to know if there is a way to retrieve the method name by a definition in this way

Eg :

 getMethodName ( MyObject.myMethod() ) -> "myMethod"

this because i would use a sort of C# delegate (achieved through java's reflection) but i'm afraid about the absence of compiler's checking, during method invocation.

But if i could retrieve safely the method's name , i should execute reflection without the risk of calling an unexisting method.

Thanks in advance for the help.

Skary
  • 1,322
  • 1
  • 13
  • 40
  • getMethodName method is containing class name as parameter ?? – Kick Jan 26 '14 at 18:26
  • Something like this for (Method method : YourClass.class.getDeclaredMethods()) { String name = method.getName(); } – Prince Jan 26 '14 at 18:33
  • @StefanoSanfilippo in other word i asked if there is a way to identify a method,but reading your reply seems that there is no way to do that. MyObject.class.getMehods() is good, but not enought to give to me information about a specific method, i mean there is no easy way to specify (safely) a method at design time, and obtain a compiler's guarantees that the method exits at runtime. – Skary Jan 26 '14 at 18:38
  • @Prince your example is pretty close to what i would. Is there a way to do "Method m = myObject.someMethod()"? And then "m.toString()"? If there is, it's exactly what i want. – Skary Jan 26 '14 at 18:56
  • There is a way to get methods and then there is a way to invoke method with params. What exactly do you want? – Prince Jan 26 '14 at 19:15
  • I would pass a method written as i try to invoke it (to ensure it exist), to an object that store and run it later, like C# delegate (because Java has no delegate i use reflection, but i need method name in a secure way). I tried to explain it better in this post on pastebin http://pastebin.com/49UzJFQL – Skary Jan 26 '14 at 20:05

0 Answers0