Android Class Field Find getAdditionalStaticField(Class clazz, String key)

Here you can find the source of getAdditionalStaticField(Class clazz, String key)

Description

get Additional Static Field

Declaration

public static Object getAdditionalStaticField(Class<?> clazz, String key) 

Method Source Code

//package com.java2s;

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 getAdditionalStaticField(Object obj, String key) {
        return getAdditionalInstanceField(obj.getClass(), key);
    }/*from   ww  w.jav a  2s.c o m*/

    public static Object getAdditionalStaticField(Class<?> clazz, String key) {
        return getAdditionalInstanceField(clazz, key);
    }

    public static Object getAdditionalInstanceField(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.get(key);
        }
    }
}

Related

  1. findField(Class clazz, String fieldName)
  2. findFieldRecursiveImpl(Class clazz, String fieldName)
  3. findFirstFieldByExactType(Class clazz, Class type)
  4. getFields(Class cs)