Consider this example:
public final class Main<T extends Main<T>> {
public static void main(String[] args) {
Main<?> main = new Main<>();
}
}
This compiles perfectly. However when I try to make this compile without using the diamond, the only way I can get it to work is by using a raw type.
Main<?> main = new Main();
Attempts without raw types don't work:
Main<?> main = new Main<?>(); // None of
Main<?> main = new Main<Main<?>>(); // these
Main<?> main = new Main<Main<Main<?>>>(); // compile
So why does the original version with the diamond work? What is the inferred type when you write Main<?> main = new Main<>();
?
Is it inferring a raw type, or is it inferring some kind of infinitely nested type like this?
Main<Main<Main<Main<...>>>>