effective-java-3e-source-code
effective-java-3e-source-code copied to clipboard
[Item 12] toString() vs. localization
I think there is one point about toString()
which could be worth being mentioned in Item 12.
- You should not misuse
toString()
for displaying objects in a user interface, since that will preclude localization. Rather usejava.text.MessageFormat
or something similar for that purpose.
This is also highlighted in the text which says that phone numbers have a standard string representation. This "standard" is actually only valid in US, Canada and the other countries with country code 1. Elsewhere in the world, phone numbers looks different.