java.util.ResourceBundle.setParent(ResourceBundle parent)%uA0方法设置此包的父包。父包,由getObject搜索时,这个包不包含特定的资源。
声明
以下是java.util.ResourceBundle.setParent()方法的声明
protected void setParent(ResourceBundle parent)
参数
-
parent%uA0-- 这个包的父包。
返回值
此方法不返回任何值。
异常
-
NA
例子
下面的示例演示java.util.ResourceBundle.setParent()方法的用法。
package com.yiibai import java.util.Enumeration import java.util.Locale import java.util.ResourceBundle import java.util.StringTokenizer public class ResourceBundleDemo extends ResourceBundle { @Override public Object handleGetObject(String key) { if (key.equals("hello")) { return "Hello World!" } else { return null } } @Override public Enumeration getKeys() { StringTokenizer key = new StringTokenizer("Hello World!") return key } @Override protected void setParent(ResourceBundle parent) { super.setParent(parent) } public static void main(String[] args) { // create a new ResourceBundle with specified locale ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US) // print the string array assigned to key "hello" System.out.println("" + bundle.getString("hello")) } }
假设在你的CLASSPATH中,资源文件hello_en_US.properties可用,包含以下内容。该文件将被用作输入到示例程序:
hello=Hello World!
让我们来编译和运行上面的程序,这将产生以下结果:
Hello World!