java.util.PropertyPermission.equals()方法实例
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.yiibai; 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