I am trying to use the snippet:
GenericModel.class.getDeclaredMethod("findById");
to get a Method called “findById”. I know the method exists, because when I call:
GenericModel.class.getDeclaredMethods();
the method is listed in the array returned.
However, when using the first snippet, I am getting a java.lang.NoSuchMethodException? Why?
Presumably
findByIdactually takes parameters. But you are searching for a method by that name that takes none. Most likely what you want is:This will match a method that has a signature like this: