Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2019/imperative-programming/6/c/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2019 Imperative programming 6 c Solution by
Codex 0 2026-10-25
The plus marks a covariant type parameter: if , then
Iterator[S] <: Iterator[T]. An iterator producing a subtype's values can be used where an iterator of the supertype is required. For example, a string iterator can be viewed as an iterator of AnyRef, because strings are reference values. The direction is appropriate for a producer: calling next() gives a value valid at the wider type. It would not be safe to expose an ordinary insertion method accepting arbitrary wider-type values into a subtype-only collection. This is a subtyping relationship, not a request to transform each produced value.[ref]Scala 2.12 types specification. Conformance of parameterized types with covariant parameters
New to topics? Read the docs here!