jeudi 14 juin 2018

java : Invoke method with an user defined class array parameter using reflection

I am attempting to write a method the executes a method by passing an array of user defined class as arguments to the method using reflection.

Class[] argTypesList = new Class[] {String[].class, String[].class, MyClass[].class};       
Method methodToExecute = classToCall.getDeclaredMethod(“Method1”, argTypesList);

Method1 is : 
Method1(String[] a, String[] b, MyClass[] myclass)

Here third param is of user defined class array.

Class myClass= Class.forName("somepackage.MyClass");

argTypesList = new Class[] {String[].class, String[].class, myClass[]};

gave below error

error: '.class' expected


with myClass[].class gives cannot find symbol for myClass





Aucun commentaire:

Enregistrer un commentaire