Is there a way to use dynamically invoke a method based on a bounded generic parameter’s type?
I’ve set the following up as an example.
I have an interface Foo
with various implementations that doThing
. I understand that polymorphism allows different implementations of Foo
to be stored in a collection of Foo
, where each can call their respective doThing
implementation. Can we do something similar based on the bounded generic parameter’s type, like I try with the Consumer<> printer
? It would be very convenient to be able to do this.