我基本上想做这样的事情:
class Shape
class CoordSystem
class C3D(val x: Double, y: Double, z: Double) extends CoordSystem
class C2D(val x: Double, y: Double) extends CoordSystem
abstract class Shape {
def getCoords[C <: CoordSystem]: List[C]
}
class Pyramid extends Shape {
def getCoords: List[C3D] =
List(new C3D(1,2,1), new C3D(1,1,1), new C3D(2,2,1), new C3D(2,1,1), new C3D(1.5,1.5,3))
}
>> error: class Pyramid needs to be abstract, since method getCoords in class Shape of type [C <: CoordSystem]List[C] is not defined
我还发现,在Schala Lang电子邮件名单上就通用s进行了令人感兴趣的讨论,但不能将其与我的情况相重。
感激之情!