📄 main.java
字号:
import java.lang.reflect.*;
class Main {
static void check(Class c) {
SecurityManager sm = System.getSecurityManager();
// Check public access.
try {
if (sm != null) {
sm.checkMemberAccess(c, Member.PUBLIC);
}
System.out.print("You do ");
} catch (SecurityException e) {
System.out.print("You don't ");
}
System.out.println("have permission to access all public "
+ "inherited and declared fields, methods, and constructors "
+ "of " + c);
// Check declared access.
try {
if (sm != null) {
sm.checkMemberAccess(c, Member.DECLARED);
}
System.out.print("You do ");
} catch (SecurityException e) {
System.out.print("You don't ");
}
System.out.println("have permission to access all declared "
+ "fields, methods, and constructors "
+ "of " + c);
}
public static void main(String[] args) {
// Access enabled.
check(Main.class);
System.setSecurityManager(new MySecurityManager());
System.out.println();
// Access disabled.
check(Main.class);
}
}
class MySecurityManager extends SecurityManager {
public void checkMemberAccess(Class clazz, int which) {
throw new SecurityException();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -