📜  Java的.lang.management.ManagementPermission类在Java中

📅  最后修改于: 2022-05-13 01:54:52.136000             🧑  作者: Mango

Java的.lang.management.ManagementPermission类在Java中

Java.lang.ManagementPermission 类包含确定对系统资源的访问的抽象方法。每个对象都有一些名称。大多数权限对象也有一些与之关联的“动作”,这些“动作”告诉这个权限对象允许哪些活动。

类声明:

public final class ManagementPermission
extends BasicPermission

构造函数:

Permission(String name)

public Permission(String name):用这个名字构造一个新的 Permission 对象。

方法:



MethodDescription 
checkGuard(Object object)It is used to determine if this Permission object can be guarded (protect access to another object) or not.
equals(Object obj)It checks whether two Permission objects are equal or not.
hashCode()It returns the hash code value for this Permission object.
getName()It returns the name of this Permission.
implies(Permission permission)It checks whether this ManagementPermssion object implies this permission or not.
newPermissionCollection()It returns a new PermissionCollection object.
toString()It returns a string representation of the specified Permission object.

1.public void checkGuard(Object object) :用于判断这个Permission对象是否可以被保护(保护对另一个对象的访问)。

Parameters:
object - the object to guard.
Throws:
SecurityException - if the access is denied by checkPermission method.

2.public abstract boolean contains(Permission permission):检查这个ManagementPermssion对象是否隐含了这个权限。

Parameters:
permission - the permission to check against.
Returns:
true if this permission is implied by this object, false otherwise.

3.public abstract boolean equals(Object obj):检查两个Permission对象是否相等。

Parameters:
obj - the object to be compared
Returns:
true if both Permission objects are equal, false otherwise.

4.public abstract int hashCode():它返回这个Permission对象的哈希码值。

Returns:
a hash code value for this object.

5.public final String getName():返回这个Permission的名字。

Returns:
the name of this Permission.

6.public abstract String getActions():以String格式返回这个Permission对象的动作。

Returns:
the actions of this Permission.

7.public PermissionCollection newPermissionCollection() :它返回一个新的PermissionCollection 对象。

Returns:
a new PermissionCollection object

8.public String toString():返回指定Permission对象的字符串表示。

Returns:
string representation of the specified Permission object.
Java
import java.lang.management.ManagementPermission;
import java.security.Permission;
  
public class GFG {
  
    public static void main(String[] args)
    {
        // Creating a new ManagementPermission object with
        // name control
        Permission p = new ManagementPermission("control");
        try {
            // Printing name of the object
            System.out.println("Name: " + p.getName());
            // Printing hash value of the object
            System.out.println("Hashcode: " + p.hashCode());
            // Printing actions of the object
            System.out.println("Actions: "
                               + p.getActions());
            // Converting this managementPermission object
            // to new PermissionCollection object
            System.out.println(
                "As a new PermissionCollection object: "
                + p.newPermissionCollection().toString());
            // Checking if new permissionCollection implies
            // managementPermission object or not
            System.out.println(
                "Implies: "
                + p.newPermissionCollection().implies(p));
        }
        catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}


输出
Name: control
Hashcode: 951543133
Actions: 
As a new PermissionCollection object: java.security.BasicPermissionCollection@5b6f7412 (
)

Implies: false