I have this Groovy snippet in my Spring application
Class.forName(com.example.Name).getDeclaredMethods().each { method ->
if (method.getName() == ('findId')) {
println method.returnType.name
println method.getName()
}
}
and interface:
public interface Find<E, D> {
E findId(D id);
}
and class:
class Name implements Find<MyType,String>{
...
}
When my code snipet is executed I expect to have only one method with returned type MyType but I have 2?
class com.example.MyType with method findId
and
class java.lang.Object with method findId
From where this findBy can come from? From the interface or from Spring? (I do not have define method findID with returnedType Object (I am sure).
And Doc of getDeclaredMethods()
Returns an array of {@code Method} objects reflecting all the * methods declared by the class or interface represented by this * {@code Class} object. This includes public, protected, default * (package) access, and private methods, but excludes inherited methods. * The elements in the array returned are not sorted and are not in any * particular order. This method returns an array of length 0 if the class * or interface declares no methods, or if this {@code Class} object * represents a primitive type, an array class, or void. The class * initialization method {@code } is not included in the * returned array. If the class declares multiple public member methods * with the same parameter types, they are all included in the returned * array.
Aucun commentaire:
Enregistrer un commentaire