查看系统中创建的字符串对象
我想查看系统中创建的字符串对象的值。为此,我使用 Xbootclasspath 选项覆盖 String.class。在我的新重写类中,我通过向每个构造函数添加 System.out.println(value) 行来修改 String.class 的构造函数,这样,
public String() {
this.offset = 0;
this.count = 0;
this.value = new char[0];
System.out.println(value);
}
但我收到了错误,
Error occurred during initialization of VM
java.lang.ExceptionInInitializerError
at java.lang.Runtime.loadLibrary0(Runtime.java:819)
at java.lang.System.loadLibrary(System.java:1030)
at java.lang.System.initializeSystemClass(System.java:1077)
Caused by: java.lang.NullPointerException
at java.lang.String.<init>(String.java:219)
at java.lang.StringBuilder.toString(StringBuilder.java:430)
at java.io.File.<clinit>(File.java:167)
at java.lang.Runtime.loadLibrary0(Runtime.java:819)
at java.lang.System.loadLibrary(System.java:1030)
at java.lang.System.initializeSystemClass(System.java:1077)
如果有人可以指出我如何查看创建的字符串对象,我会很高兴的。
I want to see the values of the created string objects in the system. To do so, I override the String.class by using Xbootclasspath option. In my new overriding class I modified constructors of String.class by adding the line System.out.println(value) to each, such that
public String() {
this.offset = 0;
this.count = 0;
this.value = new char[0];
System.out.println(value);
}
But I got the error,
Error occurred during initialization of VM
java.lang.ExceptionInInitializerError
at java.lang.Runtime.loadLibrary0(Runtime.java:819)
at java.lang.System.loadLibrary(System.java:1030)
at java.lang.System.initializeSystemClass(System.java:1077)
Caused by: java.lang.NullPointerException
at java.lang.String.<init>(String.java:219)
at java.lang.StringBuilder.toString(StringBuilder.java:430)
at java.io.File.<clinit>(File.java:167)
at java.lang.Runtime.loadLibrary0(Runtime.java:819)
at java.lang.System.loadLibrary(System.java:1030)
at java.lang.System.initializeSystemClass(System.java:1077)
If anyone can point me on how to see the created string objects, I would be really glad.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着 System.out 为空。事实上,在加载某些类时,会创建一个新的
String
并且System.out
字段尚未初始化。您应该推迟打印,或者可能只是将有关创建的字符串的信息保留在私有字段中,然后使用调试器等查看该字段。
It means
System.out
is null. In fact while loading some classes, a newString
is created and theSystem.out
field has not been yet initialized.You should deffer the printing, or may be just keep information about created string in a private field and latter have a look on this field using debugger for example.
我猜想在 System.out 初始化之前已经创建了字符串。
如果您可以在早期程序阶段忽略这些字符串,也许您可以尝试以下操作:
I guess there are Strings being created before System.out is initialized.
If you can ignore these Strings in the early program phase, maybe you could try something like: