All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nepxion.discovery.common.util.ReflectionUtil Maven / Gradle / Ivy

There is a newer version: 6.22.0
Show newest version
package com.nepxion.discovery.common.util;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @version 1.0 */ import java.lang.reflect.Field; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class ReflectionUtil { private static Map fieldCache = new ConcurrentHashMap(); public static Object getValue(Class clazz, Object instance, String name) throws NoSuchFieldException, IllegalAccessException { String key = clazz.getName() + name; Field cacheField = fieldCache.get(key); if (cacheField == null) { Field field = clazz.getDeclaredField(name); field.setAccessible(true); fieldCache.put(key, field); cacheField = field; } return cacheField.get(instance); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy