📜  Java的.net.URLPermission类在Java中

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

Java的.net.URLPermission类在Java中

URLPermission 类用于表示访问给定 URL 资源的权限。给定的URL充当权限的名称动作代表 请求方法和标头。

类声明:

public final class URLPermission
extends Permission

构造函数:

ConstructorDescription

URLPermission(String url)

This constructor is used to create a new instance of URLPermission class with the specified URL



URLPermission(String url, String actions)

This constructor is used to create a new instance of URLPermission class with the specified URL and actions

方法:

Methods

Description

equals(Object p)

This method checks whether the two URLPermission objects are equal or not.

getActions()



This method returns the actions in String format, which is currently a normalized method list and sends a request for header list.

hashCode()

This method returns the hash value of this object.

implies(Permission p)

This method checks whether the given permission is implied by this object or not.

示例 1:

Java
// Java program to illustrate working of hashCode() method
import java.net.URLPermission;
  
public class URLpermission {
  
    public static void main(String[] args)
    {
        String url = "https://www.geeksforgeeks.org";
        // creating a new URLPermission object
        URLPermission permission
            = new URLPermission(url, "connect");
        // printing the actions of this URLPermission object
        System.out.println("Actions: "
                           + permission.getActions());
        // printing the hash value of this URLPermission
        // object
        System.out.println("Hashcode: "
                           + permission.hashCode());
    }
}


Java
// Java program to illustrate working of equals() method
import java.net.URLPermission;
  
public class URLpermission {
  
    public static void main(String[] args)
    {
        String url1 = "https://www.geeksforgeeks.org";
        String url2
            = "https://www.geeksforgeeks.org/data-structure-gq/linked-list-gq/";
        URLPermission permission1 = new URLPermission(url1);
        URLPermission permission2 = new URLPermission(url2);
  
        if (permission1.equals(permission2)) {
            System.out.println("Both objects are equal");
        }
        else {
            System.out.println(
                "Both objects are not equal");
        }
    }
}


输出
Actions: CONNECT:
Hashcode: -1592744539

示例 2:

Java

// Java program to illustrate working of equals() method
import java.net.URLPermission;
  
public class URLpermission {
  
    public static void main(String[] args)
    {
        String url1 = "https://www.geeksforgeeks.org";
        String url2
            = "https://www.geeksforgeeks.org/data-structure-gq/linked-list-gq/";
        URLPermission permission1 = new URLPermission(url1);
        URLPermission permission2 = new URLPermission(url2);
  
        if (permission1.equals(permission2)) {
            System.out.println("Both objects are equal");
        }
        else {
            System.out.println(
                "Both objects are not equal");
        }
    }
}
输出
Both objects are not equal