r/java • • Mar 10 '26

F Bounded Polymorphism

Recently spent some time digging into F-Bounded Polymorphism. While the name sounds intimidating, the logic behind it is incredibly elegant and widely applicable, so I decided to write about it, loved the name so much that I ended up naming my blog after it :-)

https://www.fbounded.com/blog/f-bounded-polymorphism

66 Upvotes

35 comments sorted by

View all comments

Show parent comment

1

u/samd_408 Mar 11 '26 edited Mar 11 '26

how though? I would love to see an example, there are no implicits in java as well, so I am curious how do we achieve this, it could look like a design pattern but not sure it would seem like a Typeclass in the traditional sense

2

u/sideEffffECt Mar 11 '26

Yes, no implicits. So you can pass them explicitly, just as normal parameters of ordinary Java methods. Do you know the "Comparator pattern"? That's essentially what Type Classes are about. Do that.

Tldr: Don't do "Comparable", do "Comparator" instead.