Is there a correct way to write this code? [duplicate]

2
package linguagem;
import java.util.*;
public class Linguagem {
    public static void main(String[] args) {
        Locale locale = new Locale("PORTUGUESE", "PT");
        System.out.println("Linguagem: " + locale.getDefault());
    }
}

Withlocale.getDefault()returningen_US,itbecomesunnecessarytouseLocale("PORTUGUESE", "PT") , however, if I leave only Locale() , NetBeans returns me error.

And if I leave the string empty: Locale("", "") , it works, but it looks like gambiarra.

I wanted to know if there is another way to write this code, without having to leave the variable empty.

    
asked by anonymous 13.06.2018 / 11:53

1 answer

0

The method getDefault() is static and will always return to JVM's default locale .

I think what you really want is:

Locale locale = new Locale("portuguese", "pt");
System.out.println("Linguagem: " + locale);

Or, to get the Locale default:

Locale locale = Locale.getDefault();
System.out.println("Linguagem: " + locale);
    
13.06.2018 / 12:35