getNoFallbackControl(List<String>): This method is available in java.util.ResourceBundle.Control class of Java.
Syntax:
Control java.util.ResourceBundle.Control.getNoFallbackControl(List<String> formats)
This method takes one argument. This method returns a ResourceBundle.Control in which the getFormats method returns the specified formats and the getFallbackLocalemethod returns null.
Note: The formats must be equal to one of Control.FORMAT_PROPERTIES, Control.FORMAT_CLASS or Control.FORMAT_DEFAULT.
Parameters: One parameter is required for this method.
formats: the formats to be returned by the ResourceBundle.Control.getFormats method.
Returns: a ResourceBundle.Control supporting the specified formats with no fallback Locale support.
Throws:
1. NullPointerException - if the format is null.
2. IllegalArgumentException - if formats is unknown
Approach 1: When no exception
Java
import java.util.ArrayList;import java.util.List;import java.util.Locale;import java.util.ResourceBundle.Control;public class ResourceBundleControlgetNoFallbackControl {public static void main(String[] args) {List<String> formats = new ArrayList<String>();formats.add("java.class");Control str = Control.getNoFallbackControl(formats);System.out.println(str.toBundleName("Hello", Locale.US));}}
Output:
Hello_en_US
Approach 2: NullPointerException
Java
import java.util.List;import java.util.Locale;import java.util.ResourceBundle.Control;public class ResourceBundleControlgetNoFallbackControl {public static void main(String[] args) {List<String> formats = null;Control str = Control.getNoFallbackControl(formats);System.out.println(str.toBundleName("Hello", Locale.US));}}
Output:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.List.equals(Object)" because "formats" is null at java.base/java.util.ResourceBundle$Control.getNoFallbackControl(ResourceBundle.java:2642)
Approach 3: IllegalArgumentException
Java
import java.util.ArrayList;import java.util.List;import java.util.Locale;import java.util.ResourceBundle.Control;public class ResourceBundleControlgetNoFallbackControl {public static void main(String[] args) {List<String> formats = new ArrayList<String>();formats.add("class");Control str = Control.getNoFallbackControl(formats);System.out.println(str.toBundleName("Hello", Locale.US));}}
Output:
Exception in thread "main" java.lang.IllegalArgumentException at java.base/java.util.ResourceBundle$Control.getNoFallbackControl(ResourceBundle.java:2651)
No comments:
Post a Comment