Class ReflectiveCloner

java.lang.Object
cloud.opencode.base.deepclone.cloner.AbstractCloner
cloud.opencode.base.deepclone.cloner.ReflectiveCloner
All Implemented Interfaces:
Cloner

public final class ReflectiveCloner extends AbstractCloner
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:
  • Method Details

    • create

      public static ReflectiveCloner create()
      Creates a ReflectiveCloner with default configuration 使用默认配置创建ReflectiveCloner
      Returns:
      the cloner | 克隆器
    • create

      public static ReflectiveCloner create(ReflectiveCloner.ReflectiveConfig config)
      Creates a ReflectiveCloner with specific configuration 使用指定配置创建ReflectiveCloner
      Parameters:
      config - the configuration | 配置
      Returns:
      the cloner | 克隆器
    • doClone

      protected <T> T doClone(T original, CloneContext context)
      Description copied from class: AbstractCloner
      Performs the actual cloning logic 执行实际的克隆逻辑
      Specified by:
      doClone in class AbstractCloner
      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

      public String getStrategyName()
      Description copied from interface: Cloner
      Gets the name of the cloning strategy 获取克隆策略名称
      Returns:
      the strategy name | 策略名称
    • supports

      public boolean supports(Class<?> type)
      Description copied from interface: Cloner
      Checks if this cloner supports the given type 检查此克隆器是否支持给定类型
      Parameters:
      type - the type to check | 要检查的类型
      Returns:
      true if supported | 如果支持返回true