Reputation: 47290
Class MyClass
has a method getMyClassId
and I want to invoke something like this :
Method method = clazz.getMethod("get" + clazz.getName() + "Id");
method.invoke(myObject)
But clazz.getName() returns the fully qualified package information, I could do some string manipulation, but wondered if there was a better way ?
Upvotes: 0
Views: 66
Reputation: 4653
try
Method method = clazz.getMethod("get" + clazz.getSimpleName() + "Id");
Upvotes: 0