我记得PaulP显示了一个很酷的技巧来缩短重复的长@specialized
序列,但我不再找到原始帖子了。像我一样
trait Foo[@specialized(Int, Float, Double, Long, Char, Boolean) A]
trait Bar[@specialized(Int, Float, Double, Long, Char, Boolean) A]
有可能以某种方式对此进行别名......
type SpecDef = ???
trait Foo[SpecDef ??? A]
trait Bar[SpecDef ??? A]
答案 0 :(得分:7)
答案在对象scala.Specializable
:
import scala.{specialized => spec, Specializable => Spec}
final val MySpec = new Spec.Group((Int, Float, Double, Long, Char, Boolean))
trait Foo[@spec(MySpec) A]
trait Bar[@spec(MySpec) A]