Getting the reference address of a variable on Android
In Java, we've always had our share of undocumented fun through the sun.misc.Unsafe class . You can allocate memory, access data fast without range checks and - what this post is about - get the memory address of some object. Motivation So why would you do this in a memory managed language like Java? Well, it's arguably rare you have an actual need, however it can come it handy at times. For instance, I needed it when debugging some weird behavior on Android. I had a strong suspicion that the (insanely complex) Android life-cycle and associated serialization aspects were the cause of me seeing an object instance mutate (I.e. change its hash value). Unfortunately Android Studio doesn't support putting a watch on a variable. What I really needed was a way to document identity equality, just as we can document value equality with the hashCode() mechanism. Android specifics It's not hard to find examples of the use of sun.misc.Unsafe on the Internet . Using it on And...