title: How to check I'm inside a @specialized function or class at runtime in scala?
body: <p>Let's say I have a specialized class and an associated companion object:</p>
  <pre><code>trait Slice[@specialized +T] {
      ...
  
      override def equals(that :Any) = that match {
          case s :Slice[_] =&gt; ???
          case _ =&gt; false
      }
  }
  
  object Slice {
      def newInstance[@specialized T] = ???
  }
  </code></pre>
  <p>Is there any way to check</p>
  <ol>
  <li>Inside a method of Slice if this instance is a specialized subclass,</li>
  <li>Inside a method of Slice if another instance is a specialized subclass for the same primitive,</li>
  <li>Inside a specialized method on a companion object if I'm running an erased or specialized variant</li>
  </ol>
  <p>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.</p>
  <p>Use case 2) is particularly important, as I could resort to faster algorithms if I knew I'm comparing apples with apples. It probably <em>could</em> 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</p>
  <pre><code>trait ArraySlice[@specialized T] extends Slice[T] { ... }
  </code></pre>
  <p>that should be considered 'compatible' with Slice[T] instances as long as they are both specialized (or both erased)?</p>