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