忽略列表是同类元组的想法:
scala> def homogeneousPair[T]: (T, T) = (1, 2)
<console>:7: error: type mismatch;
found : Int(1)
required: T
def homogeneousPair[T]: (T, T) = (1, 2)
^
<console>:7: error: type mismatch;
found : Int(2)
required: T
def homogeneousPair[T]: (T, T) = (1, 2)
^
有没有办法利用类型系统来实现同质性?
object Test {
type HomogeneousPair[T] = Tuple2[T, T]
val x: HomogeneousPair[Int] = (1, 2)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句