I have used all the suggestions I could find on StackOverflow and other sites for this. I am trying to invoke a method using reflection. Here is the code for my method:
public void my_method(String[] args) {
for(int i=0; i<args.length; i++)
{
System.out.println(args);
}
}
Here is the code I used for reflection
Class[] paramStringArray = new Class[1];
paramStringArray[0] = String[].class;
String[] argu = {"hey", "there"};
Method method = cls.getDeclaredMethod("my_method", paramStringArray);
method.invoke(obj, new Object[]{argu});
My issue is that when I run the program, I see the output printed as: [Ljava.lang.String;@70a6aa31 [Ljava.lang.String;@70a6aa31
I have tried all the suggestions I could find. Can someone please help me with this?
Thanks!
Object#toString()is your keyword. Why are you trying the advanced topic of reflection when you don't yet know how to print an object? Slow down.argsis aString[]. It does not have a customtoString()method to print its contents. UseArrays.toString(args);to return a String with the contents of the array.