Consider the following example:
import java.lang.reflect.Field; public class Test { public static void main(String[] args) { C c = new C(); try { Field f = C.class.getDeclaredField("a"); f.setAccessible(true); Integer i = (Integer)f.get(c); System.out.println(i); } catch (Exception e) {} } } class C { private Integer a =6; }
It seems illogical that you are allowed access to private fields of classes with reflection. Why is this functionality available? Isn't it "dangerous" to allow such access?
java reflection private-members
Savvas Dalkitsis Aug 06 '09 at 15:13 2009-08-06 15:13
source share