Skip to content

Instantly share code, notes, and snippets.

@tulskiy
Created July 4, 2011 07:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tulskiy/1063013 to your computer and use it in GitHub Desktop.
Save tulskiy/1063013 to your computer and use it in GitHub Desktop.
Hacking java strings
public class Main {
static {
try {
String s = "Java";
String rep = "Great Java Programmer";
Field value = s.getClass().getDeclaredField("value");
value.setAccessible(true);
value.set(s, rep.toCharArray());
Field count = s.getClass().getDeclaredField("count");
count.setAccessible(true);
count.setInt(s, rep.length());
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println("Java");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment