Java疑点

Java只有值传递

// m变量的值:指向的堆对象的地址
public static void main(String[] args) {
    Integer m = 10;
    Integer n = 20;
    swap(m,n);
    System.out.println("m = " + m + ",n = " + n);
}
// Java只有值传递,对引用数据类型,值就是指向的堆对象的地址
// a和b交换了指向的堆对象,不影响m和n
static void swap(Integer a,Integer b){
    int temp = a;
    a = b;
    b = temp;
}

关于hashcode

对象的hashcode值并不是对象的地址

创建完对象之后,对象是没有hashcode的
第一次调用hashcode方法时,会产生hashcode值,hashcode值会存在对象的markwod里面
以后再调用hashcode方法得到的是同样的值

重写了Object的hashcode方法则不遵循上述,即不会存到对象的markword中

在这里插入图片描述

IDEA中debug时,这里@后面的数字并不是hashcode值.

That is objectId reported by the JVM, for details please see the JDWP specification.

Uniquely identifies an object in the target VM.
A particular object will be identified by exactly one objectID in JDWP commands and replies throughout its
lifetime (or until the objectID is explicitly disposed).
An ObjectID is not reused to identify a different object unless it has been explicitly disposed, regardless of whether
the referenced object has been garbage collected.
An objectID of 0 represents a null object.
Note that the existence of an object ID does not prevent the garbage collection of the object.
Any attempt to access a a garbage collected object with its object ID will result in the INVALID_OBJECT error code.
Garbage collection can be disabled with the DisableCollection command, but it is not usually necessary to do so.

stackoverflow
Debug时Object@xxx表示什么

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值