Invoke a method


import java.lang.reflect.Method;

public class Main {
  public static void main(String[] a) throws Exception {
    Method f = Math.class.getMethod("sqrt", new Class[] { double.class });
    try {
      Object[] args = { new Double(10) };
      Double d = (Double) f.invoke(null, args);
      double y = d.doubleValue();
      System.out.println(y);
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}

The output:


3.1622776601683795
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.