Home > AI > Language > Java >

invoke

Example code:

import java.lang.reflect.*;

public class ClassDemo {
    long att = 78655;
    public Integer show() {
        return 1;
    }
    public void showLong(Long att) {
        this.att = att;
    }



    public static void main(String[] args) {
        ClassDemo d = new ClassDemo();

        try {
            Method m = d.getClass().getMethod("show", null);
            Integer result = (Integer) m.invoke(d);
            System.out.println(result);
        } catch (Exception e) {

        }
    }
}

Leave a Reply