Ответ 1
Коробка инвариантна по типу T, но это не означает, что ничего не видно.
abstract class Box {
type T
def get: T
}
type InvariantBox = Box { type T = AnyRef }
type SortofCovariantBox = Box { type T <: AnyRef }
Что изменяет ситуацию с отклонениями, так это степень, в которой этот тип отображается, и способ его выполнения. Абстрактные типы более непрозрачны. Но вы должны играть с этими проблемами в repl, это довольно интересно.
# get a nightly build, and you need -Ydependent-method-types
% scala29 -Ydependent-method-types
abstract class Box {
type T
def get: T
}
type InvariantBox = Box { type T = AnyRef }
type SortofCovariantBox = Box { type T <: AnyRef }
// what type is inferred for f? why?
def f(x1: SortofCovariantBox, x2: InvariantBox) = List(x1, x2)
// how about this?
def g[U](x1: Box { type T <: U}, x2: Box { type T >: U}) = List(x1.get, x2.get)
И т.д.