java - 我们如何编辑 Java 内置类,例如 Java.util.Scanner?

标签 java oop core java-6

出于好奇,我想知道是否有一种方法可以编辑/修改 rt.jar 中的 Java 核心类。我在互联网上到处搜索,但没有得到相关答案。我也提到了 Covert Java(书),但我无法理解它。



另一个答案建议修补 rt.jar 我相信这不是最好的方法 - 您实际上无法分发您的应用程序(除非您已将您的应用程序竞争并使用您的应用程序交付 Java)。

要走的路是了解bootstrap classpath 这应该涵盖大多数合理的用例。

The normal Java classloaders look for classes first in the bootstrap classpath, before checking for extensions and the application classpath. By default, the bootstrap classpath consists of the "rt.jar" file and some other important JAR files that are supplied by the JRE installation. These provide all of the classes in the standard Java SE class library, along with various "internal" implementation classes.

Under normal circumstances, you don't need to concern yourself with this. By default, commands like java, javac and so on will use the appropriate versions of the runtime libraries.

Very occasionally, it is necessary to override the normal behavior of the Java runtime by using an alternative version of a class in the standard libraries. For example, you might encounter a "show stopper" bug in the runtime libraries that you cannot work around by normal means. In such a situation, it is possible to create a JAR file containing the altered class and then add it to the bootstrap classpath which launching the JVM.

关于java - 我们如何编辑 Java 内置类,例如 Java.util.Scanner?,我们在Stack Overflow上找到一个类似的问题:


ios - AudioUnitSetProperty Swift 错误

java - 在 OS X 上编译 TuxGuitar,javac 找不到包

java - 客户端-服务器-卡住按钮

python - 我是否正确使用 super() ?

oop - 处理基于 GUI 的应用程序中的不变性

java - 删除java中的临时文件

java - 在 JEditorPane 中高亮一个词

java - 想要一个 SQL 查询来了解当前 JDBC 连接命中的 Oracle RAC 节点

C# - 访问说明符 - 用于访问同一命名空间中的方法

javascript - smartGWT 错误