Generics Scala:抽象类型可以是多个其他类型的子类型吗?
给定以下Scala定义Generics Scala:抽象类型可以是多个其他类型的子类型吗?,generics,scala,Generics,Scala,给定以下Scala定义 abstract class C { type T1 <: { def m() : Int } type T2 <: { def n() : Int } } 抽象类C{ 类型T1这是否满足您的需要 type T3 <: T1 with T2 类型T3当然可以,但是类型交叉点是用编写的,而不是和 abstract class C { type T1 <: { def m() : Int } type T2 <: {
abstract class C {
type T1 <: { def m() : Int }
type T2 <: { def n() : Int }
}
抽象类C{
类型T1这是否满足您的需要
type T3 <: T1 with T2
类型T3当然可以,但是类型交叉点是用编写的,而不是和
abstract class C {
type T1 <: { def m() : Int }
type T2 <: { def n() : Int }
type T3 <: T1 with T2
}
class X extends C {
trait T1 {def m(): Int}
class T2 {def n(): Int = 3}
class T3 extends T2 with T1 {def m(): Int = 5}
}
抽象类C{
T1型
abstract class C {
type T1 <: { def m() : Int }
type T2 <: { def n() : Int }
type T3 <: T1 with T2
}
class X extends C {
trait T1 {def m(): Int}
class T2 {def n(): Int = 3}
class T3 extends T2 with T1 {def m(): Int = 5}
}