我有这样的课:
abstract class CrudResource extends Controller {
type ResourceIdType
def getAction(id: ResourceIdType) = ...
def deleteAction(id: ResourceIdType) = ...
...
}
打算像这样使用:
class Payees extends CrudResource {
type ResourceIdType = Int
...
}
我想默认ResourceIdType
为 Int,如下所示:
abstract class CrudResource extends Controller {
type ResourceIdType = Int
...
}
这样 ID 类型将是Int
除非子类像这样覆盖它:
override type ResourceId = String
但这无法编译:
error: overriding type ResourceIdType in class CrudResource, which equals Int;
type ResourceIdType has incompatible type
class Payees extends CrudResource { override type ResourceIdType = String }
有可能做我想做的事吗?我试过, in CrudResource
, type ResourceIdType <: Any = Int
,但这不是有效的语法。