Created
October 31, 2012 17:44
-
-
Save nitsanw/3988602 to your computer and use it in GitHub Desktop.
Using Unsafe to break encapsulation - step 2
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
private static final long valueFieldOffset; | |
private static final long countFieldOffset; | |
private static final long offsetFieldOffset; | |
static | |
{ | |
try | |
{ | |
valueFieldOffset = UnsafeAccess.unsafe.objectFieldOffset(String.class.getDeclaredField("value")); | |
countFieldOffset = UnsafeAccess.unsafe.objectFieldOffset(String.class.getDeclaredField("count")); | |
offsetFieldOffset = UnsafeAccess.unsafe.objectFieldOffset(String.class.getDeclaredField("offset")); | |
} | |
catch (Exception e) | |
{ | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for the blog post here: http://psy-lob-saw.blogspot.co.uk/2012/10/breaking-string-encapsulation-using.html