是整数 可以通过hashCode()方法获取
以下代码你可以看下:- public class Demo
- {
- public static void main(String[] args){
- Test t1 = new Test();
- Test t2 = new Test();
- System.out.println("t1的内存地址:"+t1.hashCode());
- System.out.println("t1的内存地址:"+Integer.toHexString(t1.hashCode()));//十六进制形式
- System.out.println("t2的内存地址:"+t2.hashCode());
- }
- }
- class Test
- {
- private int id;
- private String name;
- public Test(){}
- public Test(int id,String name){
- this.id = id;
- this.name = name;
- }
- }
复制代码 |