Created
July 4, 2011 07:31
-
-
Save tulskiy/1063013 to your computer and use it in GitHub Desktop.
Hacking java strings
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
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