Calendar.getInstance 方法未加载用户定义的区域设置类
在 JDK 6 中,
我已经为语言环境(en,AT)实现了 CalendarData_en_AT 类,这是用户定义的语言环境(未在 jre 中定义)。我看到,当我尝试使用 Calendar.getInstance()
方法加载语言环境时,它会加载 CalendarData_en.class
进一步调试时,我发现它仅选取以下语言环境:在 LocaleMetaDataInfo
类中指定
需要做什么,以便当我们调用 Calendar.getInstance(new Locale(en, AT))
时它会加载 CalendarData_en_AT.class< /code>
代码如下:
我有一个类 CalendarData_en_AT.java
public class CalendarData_en_AT extends LocaleNamesBundle{
public CalendarData_en_AT(){
}
protected final Object[][] getContents(){
return
new Object[][] {
new Object[] { "firstDayOfWeek", "2" },
new Object[] { "minimalDaysInFirstWeek", "4" }
};
}
}
已编译的类包含在 .jar 文件中,并已放置在 jre/lib/ext 中
现在,
如果我调用 Calendar.getInstance(new Locale("en","AT")).getFirstDayOfWeek()
它应该返回 2,但现在它返回 1,原因是它加载 CalendarData_en.class 由用户实现的
CalendarData_en_AT.class
提供
In JDK 6
I have implemented CalendarData_en_AT class for locale(en, AT) which is a user defined locale(not defined in jre). I see that when I try to load the locale using Calendar.getInstance()
method it loads CalendarData_en.class
When further debugged, I found that it picks up only the locales that are specified in LocaleMetaDataInfo
class
What needs to be done so that when we call Calendar.getInstance(new Locale(en, AT))
it loads CalendarData_en_AT.class
Code below:
I have a class CalendarData_en_AT.java
public class CalendarData_en_AT extends LocaleNamesBundle{
public CalendarData_en_AT(){
}
protected final Object[][] getContents(){
return
new Object[][] {
new Object[] { "firstDayOfWeek", "2" },
new Object[] { "minimalDaysInFirstWeek", "4" }
};
}
}
The compiled class is enclosed in a .jar file and have been placed in jre/lib/ext
Now from my test class
if I call Calendar.getInstance(new Locale("en","AT")).getFirstDayOfWeek()
it should return 2, but as of now it returns 1, reason being it loads CalendarData_en.class
provide by and not CalendarData_en_AT.class
which is user implemented
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您是否真的可以为
Calendar
类执行此操作。您必须创建一个符合区域敏感服务 SPI 的提供程序。
请参阅 Sun 员工的这篇博客文章,了解有关创建和打包此类服务的更多详细信息提供者
Not sure whether you can actually do this for the
Calendar
class.You'll have to create a provider conforming to the Locale Sensitive Services SPI.
Take a look at this blog post by a Sun employee for further details on creating and packaging such a provider