title: call static method given a class object in java
body: <p>If</p>
  
  <pre><code>class MyClass {
      public static void main(String[] str) {
          System.out.println("hello world");
      }
  }
  
  // in some other file and method
  Class klass = Class.forName("MyClass");
  </code></pre>
  
  <p>How can I call <code>MyClass.main</code>? I do not have the string "MyClass" at compile time, so I cannot simply call <code>MyClass.main(String[]{})</code>.</p>