Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. package blah;
  2.  
  3. import java.lang.reflect.AccessibleObject;
  4. import java.lang.reflect.Field;
  5.  
  6. public class Play {
  7.     public static void main (String[] args) throws java.lang.Exception
  8.     {
  9.         AddressExtractor addressExtractor = new AddressExtractor();
  10.         Class<? extends AddressExtractor> clazz = addressExtractor.getClass();
  11.         Field field = clazz.getDeclaredField("pointerValue");
  12.         Field type = Field.class.getDeclaredField("type");
  13.         AccessibleObject.setAccessible(new AccessibleObject[]{field, type}, true);
  14.         type.set(field, Object.class);
  15.  
  16.         Object foo = new Object();
  17.         field.set(addressExtractor, foo);
  18.  
  19.         System.out.println(Long.toBinaryString(addressExtractor.pointerValue));
  20.         System.out.println(Long.toHexString(addressExtractor.pointerValue));
  21.         System.out.println(addressExtractor.pointerValue);
  22.  
  23.         System.out.println(Long.toBinaryString(System.identityHashCode(foo)));
  24.         System.out.println(Long.toHexString(System.identityHashCode(foo)));
  25.         System.out.println(System.identityHashCode(foo));
  26.         System.out.println(foo);
  27.  
  28.         System.out.println(field.get(addressExtractor) == foo);
  29.     }
  30. }
  31.  
  32. class AddressExtractor {
  33.     public long pointerValue;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement