Understanding F-Bound polymorphism in Java

66 Views Asked by At

I learned how generics and wildcards works, but I'm having a hard time understanding the concept of F-Bound polymorphism and how to use it in the Java language.

For example, if I understood it well, given the default method compareTo(T o) of comparable, to have a different behaviour of the method based on what T actually is, instead of doing something like: if T is int do this, else if T is String do that in the method body, which can't be done, a new class that extends comparable having newclass as type parameter must be created and then inside the new class an override of compareTo(newclass o) must be createad, and the same must be done everytime a new behaviour of the method is needed. Is this correct?

I'm looking for some other simple example in practice that can help me better understand this concept and when/how to use it.

0

There are 0 best solutions below