• Post Reply Bookmark Topic Watch Topic
  • New Topic

execute the method from a generic class  RSS feed

 
Suvarchala Malgudi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three read classes with a method named getkey.

I'm using a generic method to read data from these classes. But i don't know how to invoke the getkey method on this generic class.

I'm able to get the method as follows :

Method m = genericClass.getClass().getMethod(name, parameterTypes).
But how how to run this mehod m.

Do i need to again cast the generic class and then only need to call the methods? Is there any other way.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use m.invoke to call the method using reflection.
If you can cast to the correct class and invoke the method directly then you do not need reflection and should not be using it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!