From 17e48aab62ab1d62f689fe1ffb69badf4dfe01c4 Mon Sep 17 00:00:00 2001
From: Roel Spilker @ExtensionMethod
annotation; they will all be searched for extension methods. These extension methods apply for any code that is in the annotated class.
Lombok does not (currently) have any runtime dependencies which means lombok does not (currently) ship with any useful extension methods so you'll have to make your own. However, here's one that might spark your imagination:
+
public class ObjectExtensions { public static <T> T or(T object, T ifNull) { return object != null ? object : ifNull; } }
With the above class, if you add @ExtensionMethod(ObjectExtensions.class)
to your class definition, you can write:
+
String x = null; System.out.println(x.or("Hello, World!"));
NullPointerException
; it will actually output Hello, World!
-
@f.overview>
<@f.snippets name="experimental/ExtensionMethod" />
--
cgit