【发布时间】:2018-05-11 21:22:53
【问题描述】:
给定一个类型定义T <: Serializable,为什么它不匹配所有可序列化的东西,包括可序列化实例的列表?
即给定:
case class Bar()
def foo[T <: Serializable](param1: T) = println(param1)
foo(Bar())
foo(List(Bar()))
编译器给出以下错误:
Error:(6, 2) inferred type arguments [List[A$A15.this.Bar]] do not conform to method foo's type parameter bounds [T <: Serializable]
case 类扩展了 Serializable,List 也是如此 - 为什么 Bars 列表与类型不匹配?
【问题讨论】:
标签: scala serialization