【发布时间】:2020-01-04 02:32:21
【问题描述】:
我开始缓慢地从 Java 迁移到 Scala 并面临一些问题。 其中之一是笨拙的构造函数参数。 我知道我无法避免它们,但至少我想介绍一些 像 C++ 这样的类型别名有 typename 可以在子类中使用。
case class A[E <: Throwable]
(
mappers: Map[Class[_ :< Throwable], ExceptionMapper[_ <: Throwable]]
) {
}
case class B[CompletionException]
(
mappers: Map[Class[_ :< Throwable], ExceptionMapper[_ <: Throwable]]
) extends A(mappers) {
}
所以在上面的示例中,mappers 字段的类型很糟糕,我只想在基类中输入一次。
【问题讨论】: