Memory Address of Objects in Java
This commit is contained in:
parent
960f1a578b
commit
15f10601bc
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.memaddress;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.openjdk.jol.vm.VM;
|
||||||
|
|
||||||
|
public class MemoryAddressUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void printTheMemoryAddress() {
|
||||||
|
String answer = "42";
|
||||||
|
|
||||||
|
System.out.println("The memory address is " + VM.current().addressOf(answer));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void identityHashCodeAndMemoryAddress() {
|
||||||
|
Object obj = new Object();
|
||||||
|
|
||||||
|
System.out.println("Memory address: " + VM.current().addressOf(obj));
|
||||||
|
System.out.println("hashCode: " + obj.hashCode());
|
||||||
|
System.out.println("hashCode: " + System.identityHashCode(obj));
|
||||||
|
System.out.println("toString: " + obj);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user