While refactoring one of my projects, i replaced all language ISO Codes like "en" and "de" Strings with the Locale Class and its constants Locale.ENGLISH and Locale.GERMAN to make it more refactor save and to minimize error sources. I use then locale.getLanguage() to get the ISO Code as String.
The problem that i have with this approach is the overhead of the Locale Class in form of the country and variant fields. I am considering writing my own Language Class to avoid this overhead.
Is it good practice to use a custom class, or is there already a dedicated Language Class that i missed?
You missed one of the basic priciples of programming: Don’t reinvent the wheel.
Yes, the
Localeclass can do more than you need, but the overhead is usually extremely negligible. Also, using it enables other coders to instantly understand that part of your code.