Java ResourceBundle clearCache()方法及示例

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值