Java.util.PropertyPermission.hashCode()


描述

所述java.util.PropertyPermission.hashCode()方法返回该对象的哈希码值。哈希码是根据权限名称确定的。

声明

以下是java.util.PropertyPermission.hashCode()方法的声明

public int hashCode()

参数

NA

返回值

此方法返回此对象的哈希码的整数值。

异常

NA

实例

以下示例显示了java.util.PropertyPermission.hashCode()方法的用法。

package com.tutorialspoint;

import java.util.Date;
import java.util.Hashtable;
import java.util.PropertyPermission;

public class PropertyPermissionDemo {
   private static Hashtable<PropertyPermission, Date> validity;

   public static void main(String[] args) {

      // Build property permissions validity collection
      validity = new Hashtable<PropertyPermission, Date>();
      validity.put(new PropertyPermission("java.home.usr", "read"),
      new Date(2012, 12, 31));

      // Get permissions and validity
      checkFilePermissions("java.home.usr");
   }

   private static void checkFilePermissions(String path) {

      // Hashcode is calculated by name
      PropertyPermission permission = new PropertyPermission(path, "read");
      System.out.println("Has permissions on "+path+
         " for read, Till: "+validity.get(permission));
   }
}

让我们编译并运行上面的程序,这将产生以下结果

Has permissions on java.home.usr for read, Till: Fri Jan 31 00:00:00 IST 3913