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

今天在学习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));
    }
}

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


  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值