effective-java-3e-source-code icon indicating copy to clipboard operation
effective-java-3e-source-code copied to clipboard

[Item 12] toString() vs. localization

Open mikaelstaldal opened this issue 4 years ago • 0 comments

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 use java.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.

mikaelstaldal avatar Jun 24 '20 15:06 mikaelstaldal