How can I get an address of a List?

Viewed 171

I need to check if a returned list was created once or if it's a copy of an object. Is it possible to find out it's address?

// thread 1
List<Object> list = supplier.get();
System.out.print("list: " + list + "@" + getAddress(list));

// thread 2
List<Object> list = supplier.get();
System.out.print("list: " + list + "@" + getAddress(list));

How could getAddress(list) look like? The problem is that hashCode() which normally returns an address is overridden in AbstractList, so it would return a valid hash code instead of an address.

3 Answers
Related