From c92f4fbd5cd4e72c46642d0cf268837097ffaa57 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 26 Aug 2024 10:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20ImmutableObject=20?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/annotation/ImmutableObject.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/annotation/ImmutableObject.java diff --git a/src/main/java/xyz/zhouxy/plusone/commons/annotation/ImmutableObject.java b/src/main/java/xyz/zhouxy/plusone/commons/annotation/ImmutableObject.java new file mode 100644 index 0000000..971f8ef --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/annotation/ImmutableObject.java @@ -0,0 +1,32 @@ +package xyz.zhouxy.plusone.commons.annotation; + +import java.lang.annotation.Target; + +import com.google.common.annotations.Beta; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * 标记不可变对象。根据约定,该对象的字段只能是不可变对象或基础数据类型,且都是只读的。如: + *
@ImmutableObject
+ * class Foo {
+ *     private final @Getter int intVal;
+ *     private final @Getter String stringVal;
+ *     private final @Getter LocalDate dateVal;
+ *     private final @Getter BigDecimal decimalVal;
+ * }
+ * 
+ *

+ * 如 guava 的 ImmutableList、ImmutableMap 等不可变集合,不属于此,因为其不要求包含的元素本身是不可变的。 + *

+ * + * @author ZhouXY + * @since 0.1.0 + */ +@Beta +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface ImmutableObject { +}