问题报错
can not access a member of class com.fenggf.simple.classLoader.HelloWorld with modifiers “”
Connected to the target VM, address: '127.0.0.1:56691', transport: 'socket'
My ClassLoader
Exception in thread "main" java.lang.IllegalAccessException: Class com.fenggf.simple.classLoader.MyClassLoaderTest can not access a member of class com.fenggf.simple.classLoader.HelloWorld with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
at java.lang.Class.newInstance(Class.java:436)
at com.fenggf.simple.classLoader.MyClassLoaderTest.main(MyClassLoader.java:90)
Disconnected from the target VM, address: '127.0.0.1:56691', transport: 'socket'
Process finished with exit code 1
解决方法
原因:类通过反射机制实例化时类添加 public 权限
添加权限后的结果
------------1-------------
My ClassLoader
------------2-------------
Hello World Class is Initialized
com.fenggf.simple.classLoader.HelloWorld@7f31245a
------------3-------------
输出结果:Hello World
总结
出现 with modifiers 这种单词和权限有关,例如你获取一个private 修饰的方法或字段 也会报类似的错误