vendredi 23 février 2018

How to get and invoke method with array parameters with Java reflection

I need to get and invoke the two following methods with reflection:

buildUniqueKeyFromColumnNames(Table table, String keyName, String[] columnNames)
buildUniqueKeyFromColumnNames(Table table, String keyName, String[] columnNames, String[] orderings, boolean unique)

I have tried the following, but without any luck:

Method buildUniqueKeyFromColumnNames1 = clazz.getDeclaredMethod("buildUniqueKeyFromColumnNames",
Table.class, String.class, String[].class);
Method buildUniqueKeyFromColumnNames2 = clazz.getDeclaredMethod("buildUniqueKeyFromColumnNames",
Table.class, JPAIndexHolder.class, UniqueConstraintHolder.class, String[].class, String[].class, Boolean.class);

This just resulted in NoSuchMethodException. I suspect that it has to something to do with the array parameters.

How to I get and invoke these two methods correctly using reflection?





Aucun commentaire:

Enregistrer un commentaire