Specialized instance determines custom implementation of given type containers. Usually it is used by inlined methods and gets resolved by the compiler, so threre is zero runtime cost.
For example, consider specialized stream method map, which returns different types of stream:
val floats : Float.Stream = (1 <> 9).stream.map(_.toFloat)
val longs : Long.Stream = (1 <> 9).stream.map(_.toLong)
val strings : Stream[String] = (1 <> 9).stream.map(_.toString)
- Source
- __.scala
class java.lang.Object
trait scala.Matchable
class Any
class Specialized.Primitive[Specialized.Primitive.A]
class Specialized.X.Boolean[Specialized.X.Boolean.A]
class Specialized.X.Byte[Specialized.X.Byte.A]
class Specialized.X.Char[Specialized.X.Char.A]
class Specialized.X.Short[Specialized.X.Short.A]
class Specialized.X.Int[Specialized.X.Int.A]
class Specialized.X.Long[Specialized.X.Long.A]
class Specialized.X.Float[Specialized.X.Float.A]
class Specialized.X.Double[Specialized.X.Double.A]
class Specialized.X.AnyRef[Specialized.X.AnyRef.A]