2 ms·
> What instance of polymorphism does it lack? 1) Higher-kinded. List<Integer> is OK and List<T> is OK, but T<Integer> is not. 2) Dispatch to the right method
by mrkeen 2y ago
> What instance of polymorphism does it lack?
1) Higher-kinded. List<Integer> is OK and List<T> is OK, but T<Integer> is not.
2) Dispatch to the right method based on param types. If your class exposes foo(Apple) and foo(Banana), it will not route a Fruit to either of those methods even if it is one of those specific types.
3) Return type polymorphism, which is probably the most relevant to the error-handling discussion, e.g. in this example:
fn greet() {
fail "not greeting today"
}
in another language, fail could be polymorphic over its return type - that is, if called from a function returning an Optional<>, fail itself could choose to return Optional.empty(). Or it could return the failed version of a CompletableFuture<>, or even throw a runtime exception depending on how the language was implemented.