Java force Object::toString

Sodved :

This is mentioned in one of the comments on this question: Force invocation of base class method Wondering if there as a way to force the Object.toString instead of MyClass.toString. Just want it for debugging logs (want to see if a library is creating multiple objects or re-using the same one). e.g. Something like

myObject.Object::toString()

Can this be done easily? We are using java8

John Kugelman :

No, it can't be done easily. But there's no need. If you want the hex number the default toString() method prints, call System.identityHashCode().

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=111264&siteId=1