Object handleGetObject(String key)
描述 (Description)
java.util.ListResourceBundle.handleGetObject(String key)方法从此资源包获取给定键的对象。 如果此资源包不包含给定键的对象,则返回null 。
声明 (Declaration)
以下是java.util.ListResourceBundle.handleGetObject()方法的声明
public final Object handleGetObject(String key)
参数 (Parameters)
key - 所需对象的键
返回值 (Return Value)
此方法返回给定键的对象,或null
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.util.ListResourceBundle.handleGetObject()方法的用法。
package com.iowiki;
import java.util.*;
// create a class that extends to ListResourceBundle
class MyResources extends ListResourceBundle {
// get contents must be implemented
protected Object[][] getContents() {
return new Object[][] {
{"hello", "Hello World!"},
{"bye", "Goodbye World!"},
{"goodnight", "Goodnight World!"}
};
}
}
public class ListResourceBundleDemo {
public static void main(String[] args) {
// create a new MyResources instance
MyResources mr = new MyResources();
// get the object for key hello
System.out.println("" + mr.handleGetObject("hello"));
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Hello World!