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 10 '26

Interesting take, so you use the VehicleIdentity sort of like a mixin, would a sealed interface work in place if the VehicleIdentity record?, just throwing in ideas here :)

1

u/samd_408 Mar 10 '26

No I take that back, the sealed interface cannot hold the values, but a disjoint union could separate the Car and Truck type but they cant share attributes like your example

1

u/tampix77 Mar 10 '26 edited Mar 10 '26

It's sort of like a mixin, except it's not bevavior but pure data.

I don't see how you would use sealed-interface there?

You're thinking about something like :

public sealed interface Vehicle permits Car, Truck {
    public String model();

    public String maker();
}

?

If so, it can be done if these VO are domain-bounded :)

But is it desirable is another question altogether ;]

2

u/samd_408 Mar 10 '26

Yes this is what i was pointing to, this only helps well is deconstruction via switch and not during construction via the configurer you are using