Search code examples
javagenericsself-referencejavapoet

Generate self-referencing generic type with JavaPoet


How could I generate the following:

class A extends B<A> {}

I'm stuck at constructing the ParameterizedTypeName to add the super class, I cannot seem to find a way to reference the type of A before it is constructed...

Any pointers? Is this at all possible?


Solution

  • Use Classname.get("com.example.project", "A") to get the A and ParameterizedTypeName for the B<A>.