Consider the following simplified example:
package com.test;
class B<S> {
B(Class<S> clazz) {}
}
class A<T> {
class SubB extends B<SubB> {
SubB() {
super(SubB.class);
}
}
}
Although IntelliJ is not showing any error (as it usually does when compile errors exist), the actual compilation when starting the program ends with error located in super(SubB.class);:
Error:(8, 23) java: incompatible types:
java.lang.Class<com.test.A.SubB>cannot be converted tojava.lang.Class<com.test.A<T>.SubB>
I am curious, why is this happening? And how could I solve it?
Compilation is done with AdoptOpenJDK 11.
The constructor B<A<T>.SubB>(Class<A.SubB>) is undefined<T>?SubBis made a top-level class. I suppose it would also work whenSubBis made a static nested class.SubBto be an inner class of A? Can you make it a nested class instead? (static class SubB extends B<SubB>)static class SubB. Or try casting SubB.class toClass<A<T>.SubB.