We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG说明: 1.这里读取class文件时,判断条件应该是while ((b = fis.read()) != -1),而不是!=0 2.这里没报错是因为根本没用到自定义的findClass,项目中已经存在的类直接由Launcher$AppClassLoader加载出来了 顺便提两个问题: 1.因为不在项目空间的class才会用到自定义加载器,那么没有类的格式,怎么使用它啊? 2.为啥自定义的类加载器,走自己的findClass或者由AppClassLoader加载时,不会执行被加载类的静态代码块中的打印命令呢?
The text was updated successfully, but these errors were encountered:
此处的代码应该确实是有问题,这个类是由Launcher$AppClassLoader加载的原因是在调用 loadClass()时,由父类在classPath下找到了class文件,所以没有调用子类重写的findClass方法。 1.因为不在项目空间的class才会用到自定义加载器,那么没有类的格式,怎么使用它啊? 没有类的格式,一般是使用反射的方式来使用的,你既然要加载一个class,那么这个class的方法,你自己肯定是知道的啊 Class<?> aClass = myClassLoader.loadClass("xxxxx"); Method[] declaredMethods = aClass.getDeclaredMethods(); Object o = aClass.newInstance(); Method sayHello = aClass.getDeclaredMethod("sayHello"); sayHello.invoke(o); 2.为啥自定义的类加载器,走自己的findClass或者由AppClassLoader加载时,不会执行被加载类的静态代码块中的打印命令呢? 你使用系统自带的类加载器,也不会执行静态代码块的内容,因为类还没被「初始化」,只是被加载了而已。类在「初始化」时才会去调用静态代码块的内容。
Class<?> aClass = myClassLoader.loadClass("xxxxx"); Method[] declaredMethods = aClass.getDeclaredMethods(); Object o = aClass.newInstance(); Method sayHello = aClass.getDeclaredMethod("sayHello"); sayHello.invoke(o);
Sorry, something went wrong.
No branches or pull requests
BUG说明:
1.这里读取class文件时,判断条件应该是while ((b = fis.read()) != -1),而不是!=0
2.这里没报错是因为根本没用到自定义的findClass,项目中已经存在的类直接由Launcher$AppClassLoader加载出来了
顺便提两个问题:
1.因为不在项目空间的class才会用到自定义加载器,那么没有类的格式,怎么使用它啊?
2.为啥自定义的类加载器,走自己的findClass或者由AppClassLoader加载时,不会执行被加载类的静态代码块中的打印命令呢?
The text was updated successfully, but these errors were encountered: