import java.lang.reflect.Method; public class ReflectionExample { public static void main(String[] args) throws Exception { Class<?> clazz = Class.forName("com.example.SomeClass"); Object obj = clazz.getDeclaredConstructor().newInstance(); Method method = clazz.getMethod("someMethod", String.class); String result = (String) method.invoke(obj, "Hello, World!"); System.out.println(result); } }


上一篇:
下一篇:
切换中文