Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 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.         Address address = new Address();
  10.         Class<? extends Address> clazz = address.getClass();
  11.         Field field = clazz.getDeclaredField("address");
  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(address, foo);
  18.  
  19.         System.out.println(Long.toBinaryString(address.address));
  20.         System.out.println(Long.toHexString(address.address));
  21.         System.out.println(address.address);
  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(address) == foo);
  29.     }
  30. }
  31.  
  32. class Address {
  33.     public long address;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement