Class ReflectiveCloner
java.lang.Object
cloud.opencode.base.deepclone.cloner.AbstractCloner
cloud.opencode.base.deepclone.cloner.ReflectiveCloner
- All Implemented Interfaces:
Cloner
Reflection-based deep cloner
基于反射的深度克隆器
Uses Java reflection to access and copy all fields of an object. Supports any object type without requiring Serializable interface.
使用Java反射访问和复制对象的所有字段。 支持任何对象类型,无需实现Serializable接口。
Features | 主要功能:
- No Serializable requirement - 无需Serializable
- Annotation-based field control - 基于注解的字段控制
- Field caching for performance - 字段缓存提升性能
- Transient field handling - transient字段处理
Usage Examples | 使用示例:
ReflectiveCloner cloner = ReflectiveCloner.create();
User cloned = cloner.clone(originalUser);
// With configuration
ReflectiveCloner configured = ReflectiveCloner.create(
new ReflectiveConfig(true, true, true)
);
Security | 安全性:
- Thread-safe: Yes (stateless, field cache uses synchronizedMap) - 线程安全: 是(无状态,字段缓存使用synchronizedMap)
- Since:
- JDK 25, opencode-base-deepclone V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordConfiguration for ReflectiveCloner ReflectiveCloner的配置 -
Field Summary
Fields inherited from class AbstractCloner
arrayHandler, cloneTransient, collectionHandler, customImmutableTypes, enumHandler, fieldFilter, listener, mapHandler, maxDepth, optionalHandler, policy, recordHandler, typeHandlers -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears the static field and constructor caches.static ReflectiveClonercreate()Creates a ReflectiveCloner with default configuration 使用默认配置创建ReflectiveClonerstatic ReflectiveClonerCreates a ReflectiveCloner with specific configuration 使用指定配置创建ReflectiveClonerprotected <T> TdoClone(T original, CloneContext context) Performs the actual cloning logic 执行实际的克隆逻辑Gets the name of the cloning strategy 获取克隆策略名称booleanChecks if this cloner supports the given type 检查此克隆器是否支持给定类型Methods inherited from class AbstractCloner
clone, clone, cloneArray, cloneCollection, cloneMap, getFieldFilter, getHandler, getImmutableTypes, isBuiltinImmutable, isImmutable, registerHandler, registerImmutable, setCloneTransient, setFieldFilter, setListener, setMaxDepth, setPolicy
-
Method Details
-
create
Creates a ReflectiveCloner with default configuration 使用默认配置创建ReflectiveCloner- Returns:
- the cloner | 克隆器
-
create
Creates a ReflectiveCloner with specific configuration 使用指定配置创建ReflectiveCloner- Parameters:
config- the configuration | 配置- Returns:
- the cloner | 克隆器
-
doClone
Description copied from class:AbstractClonerPerforms the actual cloning logic 执行实际的克隆逻辑- Specified by:
doClonein classAbstractCloner- Type Parameters:
T- the object type | 对象类型- Parameters:
original- the original object | 原始对象context- the clone context | 克隆上下文- Returns:
- the cloned object | 克隆的对象
-
clearCaches
public static void clearCaches()Clears the static field and constructor caches. Useful for reclaiming memory or after bulk cloning operations. 清除静态字段和构造器缓存。 适用于回收内存或批量克隆操作后。 -
getStrategyName
-
supports
-