Scala-case类继承类型

Scala-case类继承类型,scala,inheritance,types,mixins,Scala,Inheritance,Types,Mixins,有没有一种方法可以让case类接受在它混合的特性中定义的类型? 当我尝试使用普通类时,它失败了: trait myTypes{ type aType = Array[String] } abstract class ParentClass extends myTypes{ //no issue here val a:aType = Array.fill[String](7)("Hello") } //error: not found: type aType case

有没有一种方法可以让case类接受在它混合的特性中定义的类型? 当我尝试使用普通类时,它失败了:

trait myTypes{
    type aType = Array[String]
}

abstract class ParentClass extends myTypes{
    //no issue here
    val a:aType = Array.fill[String](7)("Hello")
}

//error: not found: type aType
case class ChildClass(arg:aType) extends ParentClass

//error: not found: type aType
case class ChildClass2(arg:aType) extends myTypes

不确定Scala为什么会选择这种方式,但我希望能得到一些帮助来避免这个恼人的错误。

发生这种情况是因为类型别名超出了范围:

// error: not found: type Bar
class Foo(val bar: Bar) { type Bar = String }
相反,请尝试:

class Foo(val bar: Foo#Bar) { type Bar = String }

发生这种情况的原因是类型别名超出范围:

// error: not found: type Bar
class Foo(val bar: Bar) { type Bar = String }
相反,请尝试:

class Foo(val bar: Foo#Bar) { type Bar = String }

(注释记录:)这也适用于继承:
case类ChildClass(arg:ChildClass#aType)扩展ParentClass
。是的,因为子类继承父类的类型和常规成员。(注释记录:)这也适用于继承:
case类ChildClass(arg:ChildClass#aType)扩展父类
。是的,因为子类同时继承父类的类型成员和常规成员。