6 Replies Latest reply: Jun 7, 2010 5:09 AM by EJP RSS

    Invoking method when using forName

      If you have a class like this:
      MyClass obj = new MyClass();
      Class c = obj.getClass();
      Method m = c.getMethod("MyPrintMethod", MyClass.class);
      m.invoke(obj , new String("Hello"));
      You can invoke the method by sending "obj" and a String object as parameters.

      When using forName:
      Class c = Class.forName("MyClass");
      Method m = c.getMethod("MyPrintMethod", String.class);
      m.invoke(?, new String("Hello")); // What parameter should I use as first parameter?
      you cannot send "obj" as first parameter, so what should I use instead?