Ask Your Question
0

What is the solution to avoid getting "SomeType@2f92e0f4" while printing my Java object?

asked 2021-07-25 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-04-18 17:00:00 +0000

lakamha gravatar image

To avoid getting "SomeType@2f92e0f4" while printing a Java object, you need to override the "toString()" method in your class. The "toString()" method is called when you use the object's reference directly in a print statement. By default, the "toString()" method inherited from Object class returns a String that consists of the class name, followed by the "@" sign and the hash code of the object in hexadecimal format. So, you need to provide your own implementation of the "toString()" method in your class that returns a meaningful representation of the object's state as a String.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-25 11:00:00 +0000

Seen: 14 times

Last updated: Apr 18 '21