public final class ObjectToStringConverter extends Object
Object.toString()
.
Object.toString()
should returns a string representation of the
object. In general, a string that "textually represents" the object. The
result should be a concise but informative representation that is easy for
a person to read.
Note that Object.toString()
is used for debugging purposes (Like
log files), it is not meant to represent a display-able text for the object
(for example, to display the information in user interfaces). Java
toString() implementations for basic type values should not be taken as an
example for composite objects:
Object | toString() result | Suitable | Comments | Better alternative |
---|---|---|---|---|
Integer.valueOf(1) | 1 | Yes | This is a basic data type and it is easy to see from the toString() result that is a numeric type. | N/A |
new String("Hello World") | Hello World | Yes | This is a basic data type and it is easy to see from the toString() result that is a string. | N/A |
Boolean.TRUE | true | Yes | This is a basic data type and it is easy to see from the toString() result that is a boolean. | N/A |
new Phone(38246188) | 38246188 | No | This is not a basic type but a value type object, the toString() result is ambiguous with numeric values. | Phone[value=38246188] |
@SafeVarargs public static String toString(Object subject, Property<String,?>... properties)
Object.toString()
.subject
- object to convert to stringproperties
- object's properties to includesubject
as described in Object.toString()
Copyright © 2015. All Rights Reserved.