Created
February 7, 2010 07:30
-
-
Save rahulkmr/297280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.*; | |
class Foo | |
{ | |
private int i = 10; | |
public int getI() { return i; } | |
} | |
class PrivateTest | |
{ | |
public static void main(String[] args) | |
throws Exception | |
{ | |
Foo bar = new Foo(); | |
Field[] f = | |
bar.getClass().getDeclaredFields(); | |
for (Field test : f) { | |
/* The following operation depends on | |
the installed security manager */ | |
test.setAccessible(true); | |
/* Changing i from outside the class */ | |
test.setInt(bar, 5); | |
} | |
System.out.println(bar.getI()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment