Pergunta

Java has two overloads each for String.toLowerCase and toUpperCase. One of the overloads takes a Locale as a parameter while the other one takes no parameters and uses the default locale (Locale.getDefault()).

The parameterless variants might not work as expected because case conversion respects internationalization, and the default locale is system dependent. Most notably, the lower case i is converted to an upper case dotted İ in the Turkish locale.

What is the purpose of these methods? Do the parameterless variants have any legitimate use? Or perhaps they were just a design mistake? (Not unlike several I/O APIs that use the system default character encoding by default.)

Foi útil?

Solução 3

Several blog posts suggest that default locales and charsets indeed were a design mistake and have no meaningful use.

Outras dicas

I think they're just convenience methods that will work most of the time, since apps that really need I18n are probably a small minority in the universe of java apps in the world.

If you hardcode a unix path for a File name in a java program and try to run in a windows box, you will also get wrong results and it's not java's fault.

I guess that's an implementation of write once run anywhere principle.

It makes sense, cause you can provide the default locale at JVM startup as one of the runtime parameters.

Furthermore, Java runtime has got a bunch of similar formatting methods for Dates and Numbers. (SimpleDateFormat, NumberFormat etc)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top