Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package blah;
- import java.lang.reflect.AccessibleObject;
- import java.lang.reflect.Field;
- public class Play {
- public static void main (String[] args) throws java.lang.Exception
- {
- AddressExtractor addressExtractor = new AddressExtractor();
- Class<? extends AddressExtractor> clazz = addressExtractor.getClass();
- Field field = clazz.getDeclaredField("pointerValue");
- Field type = Field.class.getDeclaredField("type");
- AccessibleObject.setAccessible(new AccessibleObject[]{field, type}, true);
- type.set(field, Object.class);
- Object foo = new Object();
- field.set(addressExtractor, foo);
- System.out.println(Long.toBinaryString(addressExtractor.pointerValue));
- System.out.println(Long.toHexString(addressExtractor.pointerValue));
- System.out.println(addressExtractor.pointerValue);
- System.out.println(Long.toBinaryString(System.identityHashCode(foo)));
- System.out.println(Long.toHexString(System.identityHashCode(foo)));
- System.out.println(System.identityHashCode(foo));
- System.out.println(foo);
- System.out.println(field.get(addressExtractor) == foo);
- }
- }
- class AddressExtractor {
- public long pointerValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement