【发布时间】:2014-10-06 13:07:03
【问题描述】:
让下面的类型别名
class Container[T]
type MyInt = Container[Int]
尝试过是否可以以及如何在类型别名中声明类型参数
type MyInt2 = Container[T <: Int] // error: ']' expected but '<:' found.
【问题讨论】:
标签: scala generics types alias
让下面的类型别名
class Container[T]
type MyInt = Container[Int]
尝试过是否可以以及如何在类型别名中声明类型参数
type MyInt2 = Container[T <: Int] // error: ']' expected but '<:' found.
【问题讨论】:
标签: scala generics types alias
你可以这样做:
type MyInt2[T <: Int] = Container[T]
对于其他成员(例如def),类型成员必须在其声明/签名(左)中声明类型参数,而不是在正文中(右)。
【讨论】: