How get method with List<SomeObject> as parameter using Reflection

java, reflection

Solution

the parameter type is `java.util.List` and not `java.util.ArrayList`

clazz.getMethod("setContacts", List.class);

It is important that you uses the actual class because you could also have the method overloaded with an ArrayList parameter

Problem

I have ``` public void setContacts(List<PersonContact> contacts) { this.contacts = contacts; } ``` A need get this method using Reflection, I have tried ``` clazz.getMethod("setContacts", ArrayList.class); ``` show the erro : ``` java.lang.NoSuchMethodException: model.person.Person.setContacts(java.util.ArrayList) ``` That's correct, the method signature is ``` setContacts(List<PersonContact> contacts) ``` So, how can I pass correct signature in getMethod?

Original source

Related problems