由bootstrapclassloader加载类(Class loading by bootstrapclassloader)

编程入门 行业动态 更新时间:2024-10-28 00:21:49
由bootstrapclassloader加载类(Class loading by bootstrapclassloader)

这是我在采访中被问到的:

如果将一个新方法添加到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().

更多推荐

本文发布于:2023-08-06 04:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1443993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   bootstrapclassloader   loading   Class

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!