While doing some researches about how to pass a object reference in android I was thinking about the following.
Let's assume I have a WeakHashmap with Long as keys. And now I put one Object into this WeakHashMap and assign it to the key 'new Long(1)' (assuming that I will save the reference to this Long).
Now another part of the application creates a new Long(1) and after that I set my first Long (that was used as key) to null.
- What would happen to the Object in the WeakHashMap?
- What if I replace Long with an own Class with a Long member and let its compare()-Method return true if its compared with another object of the same type (my own class) that has the same value in it's Long.
- Assuming that in both cases the WeakReference gets cleared. Would it make a difference if I use my second created key to access the WeakHasMap once before clearing the first on out?