Java.util.PropertyPermission.hashCode() 方法

描述

java.util.PropertyPermission.hashCode() 方法返回此对象的哈希码值。 哈希码由权限名称确定。


声明

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

public int hashCode()

参数

NA


返回值

This method returns integer value for the hash code of this object.


异常

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