- Java.lang 包類
- Java.lang - 首頁
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang 包其他內容
- Java.lang - 介面
- Java.lang - 錯誤
- Java.lang - 異常
- Java.lang 包有用資源
- Java.lang - 有用資源
- Java.lang - 討論
Java Class getProtectionDomain() 方法
描述
Java Class getProtectionDomain() 方法返回此類的 ProtectionDomain。
宣告
以下是 java.lang.Class.getProtectionDomain() 方法的宣告
public ProtectionDomain getProtectionDomain()
引數
無
返回值
此方法返回此類的 ProtectionDomain。
異常
SecurityException − 如果存在安全管理器並且其 checkPermission 方法不允許獲取 ProtectionDomain。
獲取類的 ProtectionDomain 示例
以下示例演示了 java.lang.Class.getName() 方法的使用。在此程式中,使用 forName() 方法檢索 ClassDemo 的類。使用 getName(),我們檢索了類的 ProtectionDomain 並打印出來。
package com.tutorialspoint;
import java.security.ProtectionDomain;
public class ClassDemo {
public static void main(String[] args) {
try {
Class cls = Class.forName("com.tutorialspoint.ClassDemo");
// returns the name of the class
System.out.println("Class = " + cls.getName());
// returns the ProtectionDomain of this class.
ProtectionDomain p = cls.getProtectionDomain();
System.out.println(p);
} catch(ClassNotFoundException ex) {
System.out.println(ex.toString());
}
}
}
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Class = com.tutorialspoint.ClassDemo
ProtectionDomain (file:/C:/Users/Tutorialspoint/eclipse-workspace/Tutorialspoint/bin/ <no signer certificates>)
jdk.internal.loader.ClassLoaders$AppClassLoader@5c647e05
<no principals>
java.security.Permissions@816f27d (
("java.io.FilePermission" "C:\Users\Tutorialspoint\eclipse-workspace\Tutorialspoint\bin\-" "read")
("java.lang.RuntimePermission" "exitVM")
)
獲取 ArrayList 的 ProtectionDomain 示例
以下示例演示了 java.lang.Class.getName() 方法的使用。在此程式中,檢索 ArrayList 的類。使用 getName(),我們檢索了類的 ProtectionDomain 並打印出來。
package com.tutorialspoint;
import java.security.ProtectionDomain;
import java.util.ArrayList;
public class ClassDemo {
public static void main(String[] args) {
Class cls = ArrayList.class;
// returns the name of the class
System.out.println("Class = " + cls.getName());
// returns the ProtectionDomain of this class.
ProtectionDomain p = cls.getProtectionDomain();
System.out.println(p);
}
}
輸出
讓我們編譯並執行上述程式,這將產生以下結果:
Class = java.util.ArrayList
ProtectionDomain null
null
<no principals>
java.security.Permissions@33c7353a (
("java.security.AllPermission" "<all permissions>" "<all actions>")
)
java_lang_class.htm
廣告