Java Reflection - Class.getProtectionDomain() Examples

Code Snippets Java Reflection Java 


Class:

java.lang.Class

java.lang.Objectjava.lang.Objectjava.lang.Classjava.lang.Classjava.io.SerializableSerializablejava.lang.reflect.GenericDeclarationGenericDeclarationjava.lang.reflect.TypeTypejava.lang.reflect.AnnotatedElementAnnotatedElementLogicBig

Method:

public ProtectionDomain getProtectionDomain()
Returns:
the ProtectionDomain of this class

Examples


package com.logicbig.example.clazz;

import java.security.ProtectionDomain;

public class GetProtectionDomainExample {

public static void main(String... args) {
Class<GetProtectionDomainExample> c = GetProtectionDomainExample.class;
ProtectionDomain pd = c.getProtectionDomain();
System.out.println(pd);
}
}

Output

ProtectionDomain  (file:/D:/LogicBig/example-projects/200_code-snippet-examples/java-reflection/reflection-api/target/classes/ <no signer certificates>)
java.net.URLClassLoader@85ff6
<no principals>
java.security.Permissions@2fdd54f3 (
("java.io.FilePermission" "D:\LogicBig\example-projects\200_code-snippet-examples\java-reflection\reflection-api\target\classes\-" "read")
)




package com.logicbig.example.clazz;

import java.io.Serializable;
import java.security.ProtectionDomain;

public class GetProtectionDomainExample2 {

public static void main(String... args) {
System.out.println("-- Serializable --");
Class<Serializable> c = Serializable.class;
ProtectionDomain pd = c.getProtectionDomain();
System.out.println(pd);

System.out.println("-- int --");
Class<Integer> c2 = int.class;
System.out.println(c2.getProtectionDomain());

System.out.println("-- int[] --");
Class<int[]> c3 = int[].class;
System.out.println(c3.getProtectionDomain());
}
}

Output

-- Serializable --
ProtectionDomain null
null
<no principals>
java.security.Permissions@ae77353 (
("java.security.AllPermission" "<all permissions>" "<all actions>")
)


-- int --
ProtectionDomain null
null
<no principals>
java.security.Permissions@ae77353 (
("java.security.AllPermission" "<all permissions>" "<all actions>")
)


-- int[] --
ProtectionDomain null
null
<no principals>
java.security.Permissions@ae77353 (
("java.security.AllPermission" "<all permissions>" "<all actions>")
)




See Also