怎么禁用反射机制

如何禁用反射机制
比如我有两个类:
public class B {
}
class A {
  private void test() {
  //Here do something
  }
}
在类B中,如果通过反射机制,是可以调用A中的私有方法,或者修改A的私有成员,怎么样禁止在B中使用反射来修改A中的东西呢?在网上查了下,说是用SecrityManager,但是具体怎么样用呢?望高人help me!非常感谢

------解决方案--------------------
怎么禁用反射机制看过,楼楼的类名好像写错了,应该是SecurityManager这个类,它有一个checkMemberAccess这个方法可以阻止你利用反射;
如:
 SecurityManager sm = new SecurityManager();
 sm.checkMemberAccess(Test.class, Member.PUBLIC);

前面一个为CLASS,后面需要填一个INT值,Member.PUBLIC 代表可以访问,如果是PUBLIC的话你的反射还是依然可以执行,还有一个值为DECLARED,然后再运行的时候,就会报错了。。。。。
------解决方案--------------------
noraml access using java Reflection

import java.lang.reflect.Field;

public class UseReflection {
    public static void main(String args[]) {
        Object prey = new Prey();
        try {
            Field pf = prey.getClass().getDeclaredField("privateString");
            pf.setAccessible(true);
            pf.set(prey, "Aminur test");
            System.out.println(pf.get(prey));
        } catch (Exception e) {
            System.err.println("Caught exception " + e.toString());
        }

    }
}

class Prey {
    private String privateString = "privateValue";
}


the following example is using SecurityManager to prevent the java Reflection

import java.lang.reflect.Field;
import java.security.Permission;

public class UseReflection {
    static {
        try {
            System.setSecurityManager(new MySecurityManager());
        } catch (SecurityException se) {
            System.out.println("SecurityManager already set!");
        }

    }

    public static void main(String args[]) {
        Object prey = new Prey();
        try {
            Field pf = prey.getClass().getDeclaredField("privateString");