specialized-annotation

Why are so few things @specialized in Scala's standard library?

不羁岁月 提交于 2020-05-09 18:33:09
问题 I've searched for the use of @specialized in the source code of the standard library of Scala 2.8.1. It looks like only a handful of traits and classes use this annotation: Function0 , Function1 , Function2 , Tuple1 , Tuple2 , Product1 , Product2 , AbstractFunction0 , AbstractFunction1 , AbstractFunction2 . None of the collection classes are @specialized . Why not? Would this generate too many classes? This means that using collection classes with primitive types is very inefficient, because

How to obtain the raw datatype of a parameter of a field that is specialized in Scala via reflection?

故事扮演 提交于 2019-12-22 20:43:00
问题 I have a class with a field that is specialized and is using a raw datatype. For instance a Tuple2[Int, String]: scala> class TupleReflection(val tuple: Tuple2[Int, String]) defined class TupleReflection scala> val refl = new TupleReflection((5, "hello")) refl: TupleReflection = TupleReflection@1a597ec8 I want to use reflection now to find out the type parameters of the Tuple2 inside my 'refl' instance. (I cheat a little using 'head' to get the field because I know it's the only one.) scala>

How to obtain the raw datatype of a parameter of a field that is specialized in Scala via reflection?

半城伤御伤魂 提交于 2019-12-22 20:42:20
问题 I have a class with a field that is specialized and is using a raw datatype. For instance a Tuple2[Int, String]: scala> class TupleReflection(val tuple: Tuple2[Int, String]) defined class TupleReflection scala> val refl = new TupleReflection((5, "hello")) refl: TupleReflection = TupleReflection@1a597ec8 I want to use reflection now to find out the type parameters of the Tuple2 inside my 'refl' instance. (I cheat a little using 'head' to get the field because I know it's the only one.) scala>

How to obtain the raw datatype of a parameter of a field that is specialized in Scala via reflection?

梦想与她 提交于 2019-12-06 12:25:19
I have a class with a field that is specialized and is using a raw datatype. For instance a Tuple2[Int, String]: scala> class TupleReflection(val tuple: Tuple2[Int, String]) defined class TupleReflection scala> val refl = new TupleReflection((5, "hello")) refl: TupleReflection = TupleReflection@1a597ec8 I want to use reflection now to find out the type parameters of the Tuple2 inside my 'refl' instance. (I cheat a little using 'head' to get the field because I know it's the only one.) scala> val field = refl.getClass.getDeclaredFields.head field: java.lang.reflect.Field = private final scala