public interface IEq<T> {
public abstract Boolean testEqual(final T y);
public default Boolean testNotEqual(final T y) {
return !this.testEqual(y);
}
}
public interface IOrd<T> extends IEq<T> {
public abstract Boolean lessEqualThan(final T y);
public default T min(final T y) {
if(lessEqualThan(y)) return this; // <--- ERROR: cannot convert from IOrd<T> to T
else return y;
}
}
This OOP style code is very simlilar with https://en.wikipedia.org/wiki/Bounded_quantification.
The difference is I move the external function (Fmin) to Object method (min)
My question is: Is it possible to return "this" in the generic interface (IOrd) with default implement (min: T -> T) using f-bounded quantification?
You can't return
IOrd<T>
in a method which returnT
. You have to change your signature:If you want to return
T
you must provide a way to get theT
value from your implementation class: