Take the 2-minute tour ×

I am trying to use mirroring to call a method s1 of my class MyClass, with the parameter s2. Java is complaining that String.TYPE does not exist. I checked the API and it is right: I cannot do the same thing as when I call Integer.TYPE. But how can I solve the problem then? I need partype of type String, or else the method throws an exception.

public void trying(MyClass method, String s1, String s2){
   try {
       Class cls = Class.forName("MyClass");
       Class partype[] = new Class[1];
       partype[0] = String.TYPE;
       Method meth = cls.getMethod(s1, partype);
       meth.invoke(methobj, s2);
   catch (Throwable e) {
share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

It's not a type, it's a class:

partype[0] = String.class;
share|improve this answer
Awesome! It works! Thank you :D –  FranXh May 11 '12 at 23:56
add comment

Your Answer


