Java how to call method by reflection with primitive types as arguments

To call a method with primitive types as parameters using reflection :

You could use
int.class

this.getClass().getMethod("Test",int.class).invoke(this, 10);

or Integer.TYPE

this.getClass().getMethod("Test",Integer.TYPE).invoke(this, 10);

same applies for other primitive types

Leave a Comment