javainternationalizationicu4j

Why is Locale final in Java?


The class java.util.Locale is declared as final, which means that nothing can extend it.

The ICU4J project have written an extension of this class - com.ibm.icu.util.ULocale (which is also final), but because of this it can't inherit or be used easily instead of Locale.

What would the reason for this be?


Solution

  • Extending locales is not something that can easily be done without modifying the underlying system, due to the deep integration into those systems that locales have.

    If you could extend Locale to add some additional properties, then none of the classes that currently accept a Locale would know how to handle them.

    Assuming you've got a JDK with simply Locale support and you could pass in a ULocale that has a more in-depth support (such as specifying the calendar and digits to use other than the default for the underlying locale), then you couldn't expect code that accepts a traditional JDK Locale to support those features.