I have a bunch of static method names, how do I execute them. I think I can use reflection, but how to do that?
directly from the interwebz
Class<?> class1;
    try {
        class1 = Class.forName(CLASS);
        Method method = class1.getMethod(METHOD, String.class);
        Object o = method.invoke(null, NAME);
        System.out.println(o);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With