From 17e48aab62ab1d62f689fe1ffb69badf4dfe01c4 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Fri, 6 Mar 2020 01:17:07 +0100 Subject: documentation layout fix --- website/templates/features/experimental/ExtensionMethod.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'website/templates') diff --git a/website/templates/features/experimental/ExtensionMethod.html b/website/templates/features/experimental/ExtensionMethod.html index f1d8b084..1e20c625 100644 --- a/website/templates/features/experimental/ExtensionMethod.html +++ b/website/templates/features/experimental/ExtensionMethod.html @@ -35,16 +35,18 @@ You can pass any number of classes to the @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!"));

The above code will not fail with a NullPointerException; it will actually output Hello, World! -

<@f.snippets name="experimental/ExtensionMethod" /> -- cgit