4

我记得 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]
4

1 回答 1

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]
于 2013-02-10T13:26:40.790 回答