Java.util.PropertyPermission.equals()

Python/Java学习交流群:369606713


描述

所述java.util.PropertyPermission.equals(Object OBJ)方法检查该对象是否等于OBJ。即它与此对象具有相同的名称和操作

声明

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

public boolean equals(Object obj)

参数

obj - 要检查的对象。

返回值

如果给定对象等于此对象(即相同的名称和操作),则此方法返回true。

异常

NA

实例

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

package com.tutorialspoint;

import java.util.PropertyPermission;

public class PropertyPermissionDemo {
   private static PropertyPermission permission;

   public static void main(String[] args) {

      // Build property permissions collection
      permission = new PropertyPermission("java.home.usr", "read");

      // Check file read permissions
      checkFileReadPermissions("java.home.usr");

      // Check file write permissions
      checkFileWritePermissions("java.home.usr");
   }

   private static void checkFileReadPermissions(String path) {

      // Check permissions are equal
      if(permission.equals(new PropertyPermission(path, "read"))) {
         System.out.println("Has permissions on "+path+" for read");
      }
   }

   private static void checkFileWritePermissions(String path) {

      // Check permissions are equal
      if(permission.equals(new PropertyPermission(path, "write"))) {
         System.out.println("Has permissions on "+path+" for write");
      }
   }
}

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

Has permissions on java.home.usr for read