Pages

Friday, April 1, 2011

Just Some Java Reflection Madness

import java.lang.reflect.Field;

public class Test {

  public static void main(String[] args) throws Exception {
    doStuff();
    System.out.println("Hello".equals("World"));  // --> true
  }

  public static void doStuff() throws Exception {
    Field value = String.class.getDeclaredField("value");
    value.setAccessible(true);
    value.set("Hello", "World".toCharArray());
  }

}

http://www.javaspecialists.eu/talks/oslo09/ReflectionMadness.pdf

1 comment:

Unknown said...

Same with
value.set("true", "false".toCharArray());
is way more destructive :)

Disqus for Code Impossible