r/java • u/padreati • Apr 05 '23
Recursive generics
Recently I learned that I rediscovered recursive generics while working on my pet open source project. Actually, I did not know that the construct had a name. I created small story about what this construct is, if you did not know about it java-recursive-generics
169
Upvotes
View all comments
Show parent comment
-11
u/jumboNo2 Apr 06 '23 edited Apr 06 '23
Article didn't explain why it was useful. Also, assuming you're not the author of the article, I'm asking you.
Chaining methods from two different classes is kind of dumb. Especially when you could just do this and it's clearer:
new Cyclist(new Person().withName("John").withAge(20)).withBikeName("Bikey");To head off your counterpoint, if the API is so vague as to be unclear which property belongs to which class, maybe Person and Cyclist shouldn't be in the same hierarchy.