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


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