ResourceBundle类clearCache()方法 (ResourceBundle Class clearCache() method)
Syntax:
句法:
public static final void clearCache();
public static final void clearCache(ClassLoader cl);
clearCache() method is available in java.util package.
clearCache()方法在java.util包中可用。
clearCache() method is used to clear all ResourceBundle from the cache that has been moved from the given caller class ClassLoader.
clearCache()方法用于从已从给定调用者类ClassLoader移动的缓存中清除所有ResourceBundle。
clearCache(ClassLoader cl) method is used to clear all ResourceBundle from the cache that has been moved from the given parameter class loader.
clearCache(ClassLoader cl)方法用于从已从给定参数类加载器移动的缓存中清除所有ResourceBundle。
These methods may throw an exception at the time of clearing the cache.
这些方法在清除缓存时可能会引发异常。
NullPointerException: This exception may throw when the given parameter is null exists.
NullPointerException :当给定参数为null时,可能引发此异常。
These are static methods and it is accessible with the class name and if we try to access these methods with the class object then also we will not get an error.
这些是静态方法,可以通过类名进行访问,如果尝试使用类对象访问这些方法,则也不会出错。
Parameter(s):
参数:
In the first case, clearCache(),
在第一种情况下, clearCache() ,
- It does not accept any parameter.
In the second case, clearCache(ClassLoader cl),
在第二种情况下, clearCache(ClassLoader cl) ,
- ClassLoader cl – represents the class loader.
- ClassLoader cl –代表类加载器。
Return value:
返回值:
In both the cases, the return type of the method is void – it returns nothing.
在这两种情况下,该方法的返回类型都是无效的 -它什么也不返回。
Example:
例:
// Java program to demonstrate the example
// of clearCache() method of ResourceBundle
import java.util.*;
public class ClearCacheOfResourceBundle {
public static void main(String[] args) {
// Instantiates ResourceBundle with
// some locale
ResourceBundle rb = ResourceBundle.getBundle("IncludeHelp...", Locale.FRANCE);
// Display message for the given
// key element "IncludeHelp..."
System.out.println("" + rb.getString("IncludeHelp..."));
// By using clearCache() method is to
// clear cache
ResourceBundle.clearCache();
System.out.println("Cache Operation Completed.");
// By using clearCache() method is to
// clear cache by the given class loader
ClassLoader cl = ClassLoader.getSystemClassLoader();
ResourceBundle.clearCache(cl);
System.out.println("Cache Operation Completed.");
}
}
Output
输出量
IncludeHelp… = Website
翻译自: https://www.includehelp.com/java/resourcebundle-clearcache-method-with-example.aspx