Locale constructors to Locale.of()
Create language and region locales with Locale.of() instead of deprecated constructors.
Code Comparison
✕ Deprecated constructor
Locale brazilianPortuguese =
new Locale("pt", "BR");
✓ Java 19+
Locale brazilianPortuguese =
Locale.of("pt", "BR");
See a problem with this code? Let us know.
Why the modern way wins
Supported API
Avoids deprecated constructors.
Clear construction
The named factory communicates intent.
Consistent style
Matches modern JDK value-object factories.
Old Approach
Locale constructors
Modern Approach
Locale.of()
Since JDK
19
Difficulty
Beginner
JDK Support
Locale constructors to Locale.of()
Available
Available since JDK 19 (September 2022)
How it works
Locale factory methods replace constructors deprecated in JDK 19. The factory form is clearer, aligns with other value-based APIs, and centralizes locale creation.
Related Documentation
Proof