Skip to content

Commit

Permalink
Added HasSelf util class
Browse files Browse the repository at this point in the history
  • Loading branch information
Aklakan committed Sep 23, 2024
1 parent f29a1ee commit 12b5dba
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;}.
*
* <pre>{@code
* interface MyBuilderMixin<X extends MyBuilderMixin<X>> extends HasSelf<X> {
* default X someMethod() {
* // Do something
* return self();
* }
* }
* }</pre>
*/
public interface HasSelf<T> {
@SuppressWarnings("unchecked")
default T self() {
return (T)this;
}
}

0 comments on commit 12b5dba

Please sign in to comment.