这是我在采访中被问到的:
如果将一个新方法添加到String类并编译并放入rt.jar,那么将引导类加载器加载吗?
我回答说它不会被装载,但不知道为什么。
请帮助我正确回答和解释。
Here is what I was asked in interview:
If a new method is added to String class and compiled and put in rt.jar, then will bootstrap class loader load it?
I answered that it will not get loaded but could not tell why.
Please help me with correct answer and explanation of that.
最满意答案
它将被加载。
而且不仅如此:它甚至不需要在rt.jar ,如果你将一个jar文件添加到boot-classpath(参见-Xbootclasspath/p:path ),那么你甚至可以从其他jar加载java.lang.*类文件。
这当然是一种违反JVM安全性的方法,但是你需要非常深入的访问(对rt.jar写访问或访问JVM的命令行参数),当你有这些访问时,你可以做一个不仅仅是替换String.toString() 。
It will be loaded.
And not just that: it need not even be in rt.jar, if you prepend a jar file to the boot-classpath (see -Xbootclasspath/p:path), then you can even load java.lang.* classes from other jar files.
This of course is a way to violate the security of the JVM, but you need pretty deep access (either write-access to rt.jar or access to the command line parameters of the JVM) and when you have those, you can do a lot more than just replace String.toString().
更多推荐
发布评论