您的位置:首页 > 编程语言 > Java开发

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

2017-09-10 20:24 591 查看
今天在学习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));
}
}

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐