How to get a <SomeObject> combo method as a parameter using Reflection

I have

public void setContacts(List<PersonContact> contacts) {
    this.contacts = contacts;
}

I need this method using Reflection, I tried

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

show erro:

java.lang.NoSuchMethodException: model.person.Person.setContacts(java.util.ArrayList)

Right, method signature

    setContacts(List<PersonContact> contacts)

So how can I pass the correct signature to getMethod?

+3
source share
1 answer

type of parameter java.util.List, notjava.util.ArrayList

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

It is important that you use the actual class, because you could also overload the method with the ArrayList parameter

+2
source

All Articles