I'm new to java reflection concept. I need to access one method from a particular class using Java reflection. That method has three different types of argument like this,
public void print(int start, String middle, int end) {
System.out.println(start);
System.out.println(middle);
System.out.println(end);
}
I tried to call that method like this,
...
method.invoke(null, "middle", null);
...
I got IllegalArgumentException. I know null is acceptable for wrapper type args, but I just tried this method for knowing how it is working.
So, my main question is, how to pass primitive type value to that method argument via reflection? also, how to pass default value for primitive type arg via reflection? (for eg: let's assume, I don't need end arg value during runtime, then how to pass 0 for end arg)
Is there any way to solve this issue?
Aucun commentaire:
Enregistrer un commentaire