From 83c63686d7ef6c745ed9d853e33c293f7d6bb8d5 Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 6 Apr 2023 00:34:41 +0200 Subject: Initial draft for @lombok.experimental.Memoize This is an initial draft for how an @Memoize annotation could look like. It currently lacks features such as: - Thread safety - Cache invalidation - Soft/Weak References for a lower memory profile - Avoiding using a Map entirely for parameterless methods Ideally at least some of these properties should be configurable using flags and/or annotation properties (some users might prefer a non thread safe cache for better performance). Example Usage: ```java class Test { int invocationCount = 0; public static void main(String[] args) { Test test = new Test(); System.out.println(test.x(1, 2)); System.out.println(test.x(1, 2)); System.out.println(test.x(1, 3)); System.out.println("Invocation Count: " + test.invocationCount); } @lombok.experimental.Memoize public int x(int y, int z) { invocationCount++; return y + z; } } ``` --- src/core/lombok/experimental/Memoize.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/core/lombok/experimental/Memoize.java (limited to 'src/core/lombok/experimental') diff --git a/src/core/lombok/experimental/Memoize.java b/src/core/lombok/experimental/Memoize.java new file mode 100644 index 00000000..d7f6c2e5 --- /dev/null +++ b/src/core/lombok/experimental/Memoize.java @@ -0,0 +1,11 @@ +package lombok.experimental; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.SOURCE) +public @interface Memoize { +} -- cgit