Tuesday, June 9, 2026
HomeLanguagesJavajava.lang.reflect.ReflectPermission Class in Java

java.lang.reflect.ReflectPermission Class in Java

ReflectPermission class extends BasicPermission class. It is a “named” permission i.e it contains a name but no action. It may implement actions on top of BasicPermission, if desired. It is used to get information about the behaviour of Constructors.

Constructors Description
ReflectPermission(String name) It is used to create a ReflectPermission with the specified name.
ReflectPermission(String name, String action) It is used to create a ReflectPermission with the specified name and action.

Methods inherited from class java.security.BasicPermission:

Methods Description
equals(Object obj) It checks whether the two BasicPermission objects are equal or not.
getActions() It returns the actions in String format, which is currently an empty string as there is no action for ReflectPermission.
hashCode() It returns the hash code value for this object.
implies(Permission permission) It checks whether the given permission is implied by this object or not.
newPermissionCollection() It returns a new PermissionCollection object.

Below is the example/use of a given class:

Java




// Use of java.lang.reflect.ReflectPermission Class in Java
import java.lang.reflect.ReflectPermission;
class GFG {
    public static void main(String[] args)
    {
        if (canAccessPrivateMethods()) {
            System.out.println("Permission granted");
        }
        else {
            System.out.println("Permission not granted");
        }
    }
    static boolean canAccessPrivateMethods()
    {
        try {
            SecurityManager securityManager
                = System.getSecurityManager();
            if (null != securityManager) {
                securityManager.checkPermission(
                    new ReflectPermission(
                        "suppressAccessChecks"));
            }
        }
        catch (SecurityException e) {
            return false;
        }
        return true;
    }
}


Output

Permission not granted
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6895 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS