mardi 21 avril 2015

Understanding @specialized with Non-Primitives

Looking at @specialized's docs, I see:

scala> class MyList[@specialized T]
defined class MyList

My incomplete understanding is that MyList accepts a generic parameter, T, that must be a primitive.

scala> new MyList[Int] {}
res1: MyList[Int] = $anon$1@17884d

But, I then made a case class.

scala> case class Zig(x: String)
defined class Zig

However, given my above assumption, I did not expect to be able to new a MyList with a parameterized type of Zig.

scala> new MyList[Zig]
res2: MyList[Zig] = MyList@62de73eb

What am I missing?

Aucun commentaire:

Enregistrer un commentaire