Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.lang.reflect.Method;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        Class<?> class1 = Class.forName("Rate");
        Object obj = class1.newInstance();
        for (Method m : class1.getMethods()) {
            if (m.getName().equals("myMethod")) {
                Class<?>[] parameterTypes = m.getParameterTypes();
                System.out.println(Arrays.toString(m.getParameterTypes()));
                Object methodArgs[] = new Object[parameterTypes.length];
                for (Class<?> parameterType : parameterTypes) {
                    if (parameterType == Double.TYPE) {
                        double value = 0.5;
                        methodArgs[0] = value;
                    }
                }
                Rate rate = (Rate) m.invoke(obj, methodArgs);
                System.out.println(rate.getValue());
            }
        }
    }
}

class Rate {
    private double minValue;

    public Rate myMethod(double value) {
        minValue = value;
        return this;
    }

    public double getValue() {
        return minValue;
    }
}