Class BeanUtil
java.lang.Object
cloud.opencode.base.reflect.bean.BeanUtil
Bean Utility Class
Bean工具类
Provides low-level bean operation utilities with caching.
提供带缓存的底层bean操作工具。
Features | 主要功能:
- Getter/setter discovery with caching - 带缓存的getter/setter发现
- Property name extraction - 属性名提取
- Bean introspection utilities - Bean内省工具
Usage Examples | 使用示例:
List<Method> getters = BeanUtil.getGetters(User.class);
List<Method> setters = BeanUtil.getSetters(User.class);
String propName = BeanUtil.getPropertyName(getter);
Security | 安全性:
- Thread-safe: Yes (uses ConcurrentHashMap for caching) - 线程安全: 是(使用ConcurrentHashMap缓存)
- Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)
Performance | 性能特性:
- Time complexity: O(1) for cached lookups; O(m) for first access where m is the number of methods - 时间复杂度: 缓存命中时 O(1);首次访问为 O(m),m为方法数量
- Space complexity: O(m) for the cached getter/setter maps per class - 空间复杂度: O(m),每类缓存 getter/setter 映射
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears all caches 清除所有缓存static voidclearCache(Class<?> clazz) Clears cache for specific class 清除特定类的缓存static StringextractPropertyName(Method method) Extracts property name from getter/setter 从getter/setter提取属性名getAllPropertyNames(Class<?> clazz) Gets all property names (readable or writable) 获取所有属性名(可读或可写)static MethodGets getter for a property (cached) 获取属性的getter(缓存)getGetters(Class<?> clazz) Gets all getter methods (cached) 获取所有getter方法(缓存)static Class<?> getPropertyType(Class<?> clazz, String propertyName) Gets property type from getter 从getter获取属性类型static ObjectgetPropertyValue(Object bean, String propertyName) Gets property value using getter 使用getter获取属性值getPropertyValueSafe(Object bean, String propertyName) Gets property value safely 安全获取属性值getReadablePropertyNames(Class<?> clazz) Gets all readable property names 获取所有可读属性名static MethodGets setter for a property (cached) 获取属性的setter(缓存)getSetters(Class<?> clazz) Gets all setter methods (cached) 获取所有setter方法(缓存)getWritablePropertyNames(Class<?> clazz) Gets all writable property names 获取所有可写属性名static booleanChecks if method is a getter 检查方法是否为getterstatic booleanisReadable(Class<?> clazz, String propertyName) Checks if property is readable 检查属性是否可读static booleanChecks if method is a setter 检查方法是否为setterstatic booleanisWritable(Class<?> clazz, String propertyName) Checks if property is writable 检查属性是否可写static voidsetPropertyValue(Object bean, String propertyName, Object value) Sets property value using setter 使用setter设置属性值static booleansetPropertyValueSafe(Object bean, String propertyName, Object value) Sets property value safely 安全设置属性值
-
Method Details
-
getGetters
-
getSetters
-
getGetter
-
getSetter
-
getPropertyValue
-
getPropertyValueSafe
-
setPropertyValue
-
setPropertyValueSafe
-
isGetter
Checks if method is a getter 检查方法是否为getter- Parameters:
method- the method | 方法- Returns:
- true if getter | 如果是getter返回true
-
isSetter
Checks if method is a setter 检查方法是否为setter- Parameters:
method- the method | 方法- Returns:
- true if setter | 如果是setter返回true
-
extractPropertyName
-
getReadablePropertyNames
-
getWritablePropertyNames
-
getAllPropertyNames
-
getPropertyType
-
isReadable
-
isWritable
-
clearCache
public static void clearCache()Clears all caches 清除所有缓存 -
clearCache
Clears cache for specific class 清除特定类的缓存- Parameters:
clazz- the class | 类
-