the world is a pixel
Posts tagged Hack
Java: Accessing Private Members
Nov 14th
Using reflection to change the accessibility of a private object field and access it at runtime.
import java.lang.reflect.Field; class Life { private int meaning = 42; } class Hack { public static void main(String args[]){ Life life = new Life(); try { Field field = life.getClass().getDeclaredField("meaning"); field.setAccessible(true); System.out.println(field.get(life)); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e){ e.printStackTrace(); } } }
Output:
42
Catchable fatal error: Object of class WP_Error could not be converted to string in /home/silveiraneto/silveiraneto.net/wp-content/themes/mystique/archive.php on line 37