Java tutorial
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.WeakHashMap; public class Main { private static final WeakHashMap<Object, HashMap<String, Object>> additionalFields = new WeakHashMap<Object, HashMap<String, Object>>(); public static Object removeAdditionalStaticField(Object obj, String key) { return removeAdditionalInstanceField(obj.getClass(), key); } public static Object removeAdditionalStaticField(Class<?> clazz, String key) { return removeAdditionalInstanceField(clazz, key); } public static Object removeAdditionalInstanceField(Object obj, String key) { if (obj == null) throw new NullPointerException("object must not be null"); if (key == null) throw new NullPointerException("key must not be null"); HashMap<String, Object> objectFields; synchronized (additionalFields) { objectFields = additionalFields.get(obj); if (objectFields == null) return null; } synchronized (objectFields) { return objectFields.remove(key); } } }