直接上代码 com.**.routerdemo 替换成包名
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
public class ReflectionUtils {
public static void invokeInnerStaticClass() {
try {
Class clazz = Class.forName("com.**.routerdemo.Test$InnerStaticClass");
Constructor constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
Object instance = constructor.newInstance();
Method printM = clazz.getDeclaredMethod("print", String.class);
printM.setAccessible(true);
printM.invoke(instance, "I am InnerStaticClass");
Method getNameM = clazz.getDeclaredMethod("getName");
getNameM.setAccessible(true);
System.out.println("cxx getclassname=" + getNameM.invoke(instance));
} catch (Exception e) {
System.out.println("cxx Exception >>" + e.getMessage());
}
}
public static void invokeNormalStaticClass() {
try {
Class outerCls = Class.forName("com.**.routerdemo.Test");
Constructor outerConstructor = outerCls.getDec