Can someone point me at what I should be doing under scala 2.10 in place of this deprecated type witness on Manifest?
reflect.ClassManifest.singleType(foo) <:< barManifest
Honestly, my goal here is just to replace it with something that doesn't raise a deprecation warning. I'm happy to use the new reflection API.
Here's the code in question in context, if that's important:
https://github.com/azavea/geotrellis/blob/master/src/main/scala/geotrellis/feature/op/geometry/geometry.scala#L45
If you want a fairly literal translation from manifests to type tags, you'll need to get the appropriate mirror, use it to reflect your instance, and then use the <:<
on Type
. For example:
import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.universe._
sealed trait X
case class Y(i: Int) extends X
case class Z(j: String) extends X
def filterX[A <: X: TypeTag](xs: List[X]) = xs.filter(
x => currentMirror.reflect(x).symbol.toType <:< typeOf[A]
)
And now:
scala> filterX[Z](List(Y(1), Y(2), Z("test")))
res1: List[X] = List(Z(test))
scala> filterX[Y](List(Y(1), Y(2), Z("test")))
res2: List[X] = List(Y(1), Y(2))
There may be ways you could take advantage of the new Reflection API more fully in your application, but this should work and will take care of the deprecation warnings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With