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
- {
- Address address = new Address();
- Class<? extends Address> clazz = address.getClass();
- Field field = clazz.getDeclaredField("address");
- Field type = Field.class.getDeclaredField("type");
- AccessibleObject.setAccessible(new AccessibleObject[]{field, type}, true);
- type.set(field, Object.class);
- Object foo = new Object();
- field.set(address, foo);
- System.out.println(Long.toBinaryString(address.address));
- System.out.println(Long.toHexString(address.address));
- System.out.println(address.address);
- 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(address) == foo);
- }
- }
- class Address {
- public long address;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement