只有当
示例:在类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 楼答案
该javadoc for Currency#getInstance解释:
如果你检查Locale#forLanguageTag javadoc:
如果最后你提到how those tags work,你会看到“it”是意大利语,“it_it”是意大利语