Java Generics and Inheritance recursion

generics, java

Solution

It is almost clear and the question actually conists in two parts:

1) why `B extends A`?

2) why `A` inside `B extends A<B>` has generic type `B`?

Answers for these parts will be:

1) In particular example this class (`A`) is builder class (called `DBMaker`), so most of its methods return some type, which extends this builder's class type. This explains, why `B` should extend `A` class.

2) But, actualy, if we will hide for the second part `...extends A<B>`, we will receive just `class A<B>`. So `A` has type variable of type `B`. That is why in `...extends A<B>` A is marked as type `A` having type variable `B`.

Problem

I came across the following Java code that uses generics and inheritance. I truly do not understand what the following snippet does: ``` class A<B extends A<B>> { ... } ``` What does this code do? (I got this from DBMaker in MapDB)

Original source

Related problems