gpt4 book ai didi

java - 系统属性 : user. 地区或用户.国家

转载 作者:行者123 更新时间:2023-11-30 04:00:39 24 4
gpt4 key购买 nike

我搜索了默认区域设置的系统属性。我发现很多地方都是这样的:user.language(它有效)和user.region(不起作用)。经过更深入的搜索,我发现了一个 user.country (这有点起作用 - 返回了 user.region 应该返回的结果)。

那怎么样呢?这些引用资料都是错误的还是我错过了什么?

最佳答案

您应该能够直接在JDK源代码中看到计算默认Locale所涉及的系统属性:

public static Locale getDefault() {
// do not synchronize this method - see 4071298
// it's OK if more than one default locale happens to be created
if (defaultLocale == null) {
String language, region, country, variant;
language = AccessController.doPrivileged(
new GetPropertyAction("user.language", "en"));
// for compatibility, check for old user.region property
region = AccessController.doPrivileged(
new GetPropertyAction("user.region"));
if (region != null) {
// region can be of form country, country_variant, or _variant
int i = region.indexOf('_');
if (i >= 0) {
country = region.substring(0, i);
variant = region.substring(i + 1);
} else {
country = region;
variant = "";
}
} else {
country = AccessController.doPrivileged(
new GetPropertyAction("user.country", ""));
variant = AccessController.doPrivileged(
new GetPropertyAction("user.variant", ""));
}
defaultLocale = getInstance(language, country, variant);
}
return defaultLocale;
}

从代码来看,始终使用 user.language。 user.region 似乎已被 user.country 和 user.variant 弃用。然而,它是出于兼容性原因而使用的。代码注释应提供足够的信息来了解区域和国家/地区属性的工作原理。

关于java - 系统属性 : user. 地区或用户.国家,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22083012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com