This is just for general knowledge and I am pretty sure it may not be possible, but I am curious to know.
Suppose I have a Student class object s1
and I pass it to a function as myFunc(s1.toString())
. I haven't overrided toString()
function. When the parameter will reach to the function, can I reference back to the original object just by it's address?
code:
public static void main(){
Student s1;
myFunc(s1.toString());
}
public static myFunc(String address){
Student s2;
s2 = //get s1 object from address string
}
While the default hashcode in the common implementations does use the object address to generate it, it's not reversible (and the address being used is an implementation detail, not a specified functionality).
Even if it were possible, the address of an object can change during the runtime (whereas the default hashcode doesn't), so it wouldn't be a viable approach even if there were a way to reverse it.