mercredi 18 novembre 2020

ArrayList

ArrayList<Integer> intList = new ArrayList<>();
intList.getClass().getDeclaredMethod("add", Integer.class); // throws NoSuchMethodException

//where as
intList.getClass().getDeclaredMethod("add", Object.class); // is just fine.

Of course in this case I want the first one to work. Or at least figure out how get a method from a generic type parameter.

When looping over the declared methods the add method does explicitly say Object:

public boolean java.util.ArrayList.add(java.lang.Object)

My guess is I am missing something simple.





Aucun commentaire:

Enregistrer un commentaire