Java ResourceBundle .handleGetObject (String key)

Syntax

ResourceBundle.handleGetObject(String key) has the following syntax.

protected abstract Object handleGetObject(String key)

Example

In the following code shows how to use ResourceBundle.handleGetObject(String key) method.


/*from   ww w. j ava2 s .c  o m*/
import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;

class MainResourceBundle extends ResourceBundle {
   
   @Override
   public Object handleGetObject(String key) {
      if (key.equals("hello")) {
         return "Hello from java2s.com!";
      } else {
         return null;
      }
   }
   
   @Override
   public Enumeration getKeys() {
      StringTokenizer key = new StringTokenizer("Hello from java2s.com!");
      return key;
   }
   

}
public class Main{
  public static void main(String[] args) {

    ResourceBundle bundle =
        MainResourceBundle.getBundle("hello", Locale.US);

    System.out.println(bundle.getString("hello"));
    
 }
}