Interface CloneStrategy


public interface CloneStrategy
Strategy interface for object cloning (SPI) 对象克隆策略接口(SPI)

Implementations provide different cloning approaches such as reflection-based, serialization-based, or Unsafe-based cloning.

实现提供不同的克隆方法,如基于反射、基于序列化或基于Unsafe的克隆。

Features | 主要功能:

  • Strategy naming - 策略命名
  • Type support checking - 类型支持检查
  • Priority ordering - 优先级排序

Usage Examples | 使用示例:

public class CustomStrategy implements CloneStrategy {
    @Override
    public String name() {
        return "custom";
    }

    @Override
    public <T> T clone(T original, CloneContext context) {
        // Custom cloning logic
    }
}

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
Since:
JDK 25, opencode-base-deepclone V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    clone(T original, CloneContext context)
    Clones the object using this strategy 使用此策略克隆对象
    Gets the name of this strategy 获取此策略的名称
    default int
    Gets the priority of this strategy 获取此策略的优先级
    default boolean
    supports(Class<?> type)
    Checks if this strategy supports the given type 检查此策略是否支持给定类型
  • Method Details

    • name

      String name()
      Gets the name of this strategy 获取此策略的名称
      Returns:
      the strategy name | 策略名称
    • clone

      <T> T clone(T original, CloneContext context)
      Clones the object using this strategy 使用此策略克隆对象
      Type Parameters:
      T - the object type | 对象类型
      Parameters:
      original - the original object | 原始对象
      context - the clone context | 克隆上下文
      Returns:
      the cloned object | 克隆的对象
    • priority

      default int priority()
      Gets the priority of this strategy 获取此策略的优先级

      Lower values indicate higher priority. Default is 100.

      较小的值表示较高的优先级。默认值为100。

      Returns:
      the priority | 优先级
    • supports

      default boolean supports(Class<?> type)
      Checks if this strategy supports the given type 检查此策略是否支持给定类型
      Parameters:
      type - the type to check | 要检查的类型
      Returns:
      true if supported | 如果支持返回true