Postingan

Menampilkan postingan dengan label java tips

10 Tips to override toString() method in Java - ToStringBuilder Netbeans Eclipse

Gambar
Java toString method toString method in Java is used to provide clear and concise information about Objects in a human-readable format. A correctly overridden toString method can help in logging and debugging Java programs by providing valuable and meaningful information. Since toString() is defined in java.lang.Object class and its default implementation don't provide much information, it's always a best practice to override the toString method in a subclass. In fact, if you are creating value class or domain class e.g. Order, Trade or Employee,  always override equals,hashCode, compareTo, and toString method in Java. By default toString implementation produces output in the form package.class@hashCode like for our toString() example, Country class’ toString() method will print test.Country@18e2b22 where 18e2b22 is hashCode of an object in hex format, if you call hashCode method it will return 26094370, which is thedecimal equivalent of 18e2b22. This information is not very ...