Created
January 3, 2013 10:40
-
-
Save peter-lawrey/4442523 to your computer and use it in GitHub Desktop.
A horrible hack to change a String.
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.Field; | |
class MainClass { | |
// requires Java 7 update 5+ | |
static { | |
try { | |
Field value = String.class.getDeclaredField("value"); | |
value.setAccessible(true); | |
value.set("B", value.get("ABC")); | |
} catch (Throwable e) { | |
throw new AssertionError(e); | |
} | |
} | |
public static void main(String[] args) { | |
System.out.println("B"); // prints ABC | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment