java.lang.instrument ASSERTION FAILED ***: "error == JVMTI_ERROR_NONE" at Reentrancy.c line: 161

来源:互联网 发布:单片机数码管接线 编辑:程序博客网 时间:2024/05/29 14:02

今天在学习System类的identityHashCode()时,写了如下程序,但遇到了如题所示的错误。

该程序主要是比较String类建立对象的不同方式的区别,以及identityHashCode()方法和重写的hashCode()方法的区别,具体程序如下。

package com.iris.demo;public class IdentityHashCodeTest {    public static void main(String[] args)    {        //下面程序中的s1和s2是两个不同的对象        String s1=new String("Hello");        String s2=new String("Hello");        //String重写了hashCode()方法,改为根据字符序列计算hashCode()值        //因为s1和s2的字符序列相同,所以它们的HashCode值相同        System.out.println(s1.hashCode()+"---"+s2.hashCode());        //s1和s2是不同的字符串对象,所以它们的identityHashCode值不同        System.out.println(System.identityHashCode(s1)+"---"+System.identityHashCode(s2));        String s3="java";        String s4="java";        //s3和s4是相同的字符串对象,所以它们的identityHashCode值相同        System.out.println(System.identityHashCode(s3)+"---"+System.identityHashCode(s4));        System.out.println(s3.equals(s4));    }}

运行结果如图所示,第一次运行正常,第二次就出现了如下红色部分,再运行也是好的,说明是偶然事件。。。目前还不直到什么意思,先记录一下。


阅读全文
1 0
原创粉丝点击