是否可以参数化一个或多个特征以进行混合?我下面的示例无法编译,但 IntelliJ 的智能感知确实提供了正确的类型。
class Student
class Students[A <: Student] {
def create = new Student with A
}
trait Major extends Student
trait Dormitory extends Student
trait Fraternity extends Student
val onCampus = new Students[Major with Dormitory]
val fratBoys = new Students[Major with Fraternity]
onCampus.create // is a: Student with Major with Dormitory
fratBoys.create // is a: Student with Major with Fraternity