3

我正在尝试创建一个泛型工厂方法,该方法具有方法的上限,该方法采用该泛型类型的参数并返回该泛型类型的某些内容。我试过这个,

def apply[Type <: {def *(that: Type): Type}](length: Int)(implicit manifest: Manifest[Type]) = new Array[Type](length)

但我得到这个错误,

Parameter type in structural refinement may not refer to an abstract type defined outside that refinement

有没有办法使这项工作?

4

1 回答 1

0

根据该错误消息,您应该定义*为这样的通用函数: def apply[Type <: {def *[Type](that: Type): Type}](length: Int)(implicit manifest: Manifest[Type]) = new Array[Type](length)

于 2012-11-23T07:11:00.127 回答