As Java doesn't provide a way to get the address of the object, is it feasible to code an XOR linked list?
If yes, can someone please elaborate, how to do that?
You can never do this in Java.
Even if you use sun.misc.Unsafe
to get access to the real addresses of the objects, and even if you use a garbage collector that won't move objects around (Concurrent Mark Sweep doesn't move objects, I believe, as it's "non-compacting"), you have a bigger problem: By mangling the prev
and next
object references together in an integer, the garbage collector won't realize that they are object references. So it will think the referred objects are unreferenced, and consequently, will collect all your list nodes as garbage.
If you need to save memory, use an array-based list instead of a linked list.