From 12b5dbaf3d170a3388a4f1f26f4dc3700141b687 Mon Sep 17 00:00:00 2001 From: Claus Stadler Date: Mon, 23 Sep 2024 12:28:09 +0200 Subject: [PATCH] Added HasSelf util class --- .../org/aksw/commons/util/obj/HasSelf.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 aksw-commons-utils-parent/aksw-commons-utils/src/main/java/org/aksw/commons/util/obj/HasSelf.java diff --git a/aksw-commons-utils-parent/aksw-commons-utils/src/main/java/org/aksw/commons/util/obj/HasSelf.java b/aksw-commons-utils-parent/aksw-commons-utils/src/main/java/org/aksw/commons/util/obj/HasSelf.java new file mode 100644 index 00000000..4b130eae --- /dev/null +++ b/aksw-commons-utils-parent/aksw-commons-utils/src/main/java/org/aksw/commons/util/obj/HasSelf.java @@ -0,0 +1,20 @@ +package org.aksw.commons.util.obj; + +/** This interface is useful for builders of the form below, in order to hide + * the uncheck cast warning of {@code return (X)this;}. + * + *
{@code
+ * interface MyBuilderMixin> extends HasSelf {
+ *   default X someMethod() {
+ *      // Do something
+ *      return self();
+ *   }
+ * }
+ * }
+ */ +public interface HasSelf { + @SuppressWarnings("unchecked") + default T self() { + return (T)this; + } +}