2
我有两个抽象类,它们将保存对彼此的引用。如何/我可以键入绑定类型成员,以便派生的十六进制类的SideT成员中的HexT类型将始终是派生的Hex类?因此对于派生类HexA,保证:HexA#SideT#HexT = HexA斯卡拉抽象类型边界交叉引用
类似地,所有派生的Side类的HexT成员中的SideT类型都将是派生的Side类:SideB#HexT# SideT = SideB
我使用Scala for Eclipse 2.1.0.M1和Eclipse 3.7.2所有类都在单独的文件中。下面编译确定,但并不能保证什么,我想:
abstract class Hex { type SideT <: Side {type HexT <= Hex } }
abstract class Side { type HexT <: Hex {type SideT <= side } }
class HexC() extends Hex() { type SideT = SideC }
class SideC extends Side { type HexT = HexC }
但下面不会派生实现编译:
abstract class Hex{type SideT <: Side {type HexT = this.type}}
abstract class Side{type HexT <: Hex {type SideT = this.type}}
class HexC() extends Hex(){
type SideT = SideC //This won't compile
}
class SideC extends Side {
type HexT = HexC //this won't compile
}
这是正确的吗?如果这个编译?
对不起,我不明白上面两个解决方案。仍然引导我对Scala的理解。我以前看过= = =组合,但找不到引用。有趣的是,我在C#中尝试了第三个soln月。 C#编译器不会接受它。如果可能的话,我想在十六进制和Side中使用抽象类型,尽管我将使用包含它们的集合的泛型。 –