有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

只有当

示例:在类Currency中有一个静态方法getInstance(Locale locale)。 然而,如果我写下这样的话:

Currency currency = Currency.getInstance(Locale.forLanguageTag("it"));

它给出了一个例外(IllegalArgument.)

另一方面:

Currency currency = Currency.getInstance(Locale.forLanguageTag("it-IT"));

编译没有问题

我们可以放心地说,如果没有国家代码和地区,它是不完整的吗

请注意,在某些情况下,指定唯一的语言是构建语言环境的有效选项:

Locale localize = Locale.forLanguageTag("it");
    System.out.println(localize.getDisplayName());

共 (1) 个答案

  1. # 1 楼答案

    javadoc for Currency#getInstance解释:

    Returns the Currency instance for the country of the given locale. The language and variant components of the locale are ignored

    如果你检查Locale#forLanguageTag javadoc

    Returns a locale for the specified IETF BCP 47 language tag string.

    如果最后你提到how those tags work,你会看到“it”是意大利语,“it_it”是意大利语