Yes, it can be done (sort of, see below). (In the C ++ world, this is called a " Curiously Repeating Pattern Template ", but it also applies in Java):
public interface Recur<T extends Recur<T>> {
(Note the second mention of T This is an important part of CRTP.)
It is also a java.util.Enum definition, so an enum type called Foo must be inferred from Enum<Foo> , so it is also not an unusual template in Java.
I would like to say that the above is the end of the story, but the tangent rightly indicates in its revision that it is not completely stable and indeed not everything that differs from their answer in character.
There is one difference (I can think of) between the Recur<T> solution that I have and the Recur<?> Solution that has a touch:
public interface Recur<T extends Recur<T>> { T foo(); } class A implements Recur<B> { @Override public B foo() { return new B(); } } class B implements Recur<A> { @Override public A foo() { return new A(); } }
With <T> above will not compile; with <?> that would be. But this is just splitting hair; it does not change the center point of the tangent, which is specified by an existing Recur implementation, you can make subsequent implementations a used existing type, and not by itself. I still say that it costs something, but it does not cost more than tangent.
In conclusion, let's answer and, if you can, answer. (tangents, you must touch your message so that I can also promote you). They have a very good moment, and I'm sorry that I missed it for the first time. Thank you tangents!