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! ;-)