Brian Mearns
1 min readOct 16, 2019

--

Good question! Yes, the human would need to be aConsumer<Matter> in order for that call to be valid. The code as shown:

feed(human, boxOfBrokenGlass);

Actually give an “incompatible equality constaint” error because the type parameters on the two arguments don’t match, as required by the feed method.

However, casting it as you’ve shown gives to the “incompatible type” error (or sometime “inconvertible type”) because the compiler can’t decide if the human, typed as a Consumer<Food> can actually function as a Consumer<Matter>; and a good thing, too, otherwise we’d be free to feed broken glass to a human! ;-)

--

--

Brian Mearns
Brian Mearns

Written by Brian Mearns

Software Engineer since 2007 ・ Parent ・ Mediocre Runner ・ Flower and Tree Enthusiast ・ Crappy Wood Worker ・ he/him or they/them

No responses yet