10 Tips to override toString() method in Java - ToStringBuilder Netbeans Eclipse
Java toString method
toString method in Java is used to provide clear and concise information about Object in human readable format. A correctly overridden toString method can help in logging and debugging of Java program 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 sub class. 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 e.g. 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 decimal equivalent of 18e2b22. This information is not very useful while troubleshooting any problem.
Comments
Post a Comment
-Berkomentarlah yang baik dan rapi.
-Menggunakan link aktif akan dihapus.