Enum Class FieldCloneStrategy
- All Implemented Interfaces:
Serializable, Comparable<FieldCloneStrategy>, Constable
Enumeration of field cloning strategies
字段克隆策略枚举
Defines how individual fields should be handled during object cloning. Can be determined from field annotations or explicitly specified.
定义对象克隆期间如何处理各个字段。可以从字段注解确定或显式指定。
Usage Examples | 使用示例:
Field field = MyClass.class.getDeclaredField("data");
FieldCloneStrategy strategy = FieldCloneStrategy.fromAnnotations(field);
switch (strategy) {
case DEEP -> deepCloneField(field, source, target);
case SHALLOW -> shallowCopyField(field, source, target);
case IGNORE -> {} // Skip the field
case NULL -> setFieldNull(field, target);
}
Features | 主要功能:
- Annotation-based strategy detection - 基于注解的策略检测
- Four clone modes: DEEP, SHALLOW, IGNORE, NULL - 四种克隆模式
- Priority-based annotation resolution - 基于优先级的注解解析
Security | 安全性:
- Thread-safe: Yes (enum is immutable) - 线程安全: 是(枚举不可变)
- Since:
- JDK 25, opencode-base-deepclone V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldCloneStrategyfromAnnotations(Field field) Determines the clone strategy from field annotations 从字段注解确定克隆策略static FieldCloneStrategyReturns the enum constant of this class with the specified name.static FieldCloneStrategy[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
DEEP
Deep clone the field (default behavior) 深度克隆字段(默认行为) -
SHALLOW
Shallow copy (reference only) 浅拷贝(仅复制引用) -
IGNORE
Ignore the field (keep default value) 忽略字段(保持默认值) -
NULL
Set field to null explicitly 显式设置字段为null
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
fromAnnotations
Determines the clone strategy from field annotations 从字段注解确定克隆策略Priority order: @CloneIgnore > @CloneReference > @CloneDeep > DEEP
优先级顺序:@CloneIgnore > @CloneReference > @CloneDeep > DEEP
- Parameters:
field- the field to analyze | 要分析的字段- Returns:
- the determined strategy | 确定的策略
-