Java Reference
In-Depth Information
of arrays of
Object
. The keys must be strings, but the resources can be
any kind of object. The
ListResourceBundle
takes this array and builds the
maps for the various "get" methods. The following classes use
ListRe-
sourceBundle
to define a few locales for
GlobalRes
. First, the base bundle:
public class GlobalRes extends ListResourceBundle {
public static final String HELLO = "hello";
public static final String GOODBYE = "goodbye";
public Object[][] getContents() {
return contents;
}
private static final Object[][] contents = {
{ GlobalRes.HELLO, "Ciao" },
{ GlobalRes.GOODBYE, "Ciao" },
};
}
This is the top-level bundlewhen no other bundle is found, this will be
used. We have chosen Italian for the default. Before any "get" method is
executed,
GlobalRes.getContents
will be invoked and the
contents
array's
values will seed the data structures used by the "get" methods.
ListRe-
sourceBundle
uses an internal lookup table for efficient access; it does
not search through your array of keys. The
GlobalRes
class also defines
the constants that name known resources in the bundle. Here is another
bundle for a more specific locale:
public class GlobalRes_en extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
private static final Object[][] contents = {
{ GlobalRes.HELLO, "Hello" },
{ GlobalRes.GOODBYE, "Goodbye" },