Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java force Object::toString

Tags:

java

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

like image 833
Sodved Avatar asked Aug 16 '26 06:08

Sodved


1 Answers

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().

like image 176
John Kugelman Avatar answered Aug 18 '26 20:08

John Kugelman