Let's say I have a specialized class and an associated companion object:
trait Slice[@specialized +T] {
...
override def equals(that :Any) = that match {
case s :Slice[_] => ???
case _ => false
}
}
object Slice {
def newInstance[@specialized T] = ???
}
Is there any way to check
- Inside a method of Slice if this instance is a specialized subclass,
- Inside a method of Slice if another instance is a specialized subclass for the same primitive,
- Inside a specialized method on a companion object if I'm running an erased or specialized variant
without resorting to ClassTags or passing Class[_] manually? It seems like that information should be available, but the only way I can think of involves checking names of the classes.
Use case 2) is particularly important, as I could resort to faster algorithms if I knew I'm comparing apples with apples. It probably could be accomplished by reflection, but it would be quite tricky when you take into account that we have to handle non-synthetic subclasses of Slice, too; if we have also
trait ArraySlice[@specialized T] extends Slice[T] { ... }
that should be considered 'compatible' with Slice[T] instances as long as they are both specialized (or both erased)?
x.getClass.getName.endsWith("$sp")
? I use this in some unit tests to make sure that specialization works (but from the outside) – Burtis