title: Check the runtime type of Scala class instance
body: <p>If I run the following code, then I get an error:</p>
  <pre><code>import scala.reflect.ClassTag
  
  class General {
    
  }
  
  class SubGeneral extends General {
    def test() = println(&quot;tested&quot;)
  }
  
  
  class ProGeneral[T &lt;: General: ClassTag] {
  
    var array = Array.ofDim[T](3, 3)
    
    def funcForSubGeneral(): Unit =
          if (array(0)(0).isInstanceOf[SubGeneral]) then array(0)(0).test()
      
  }
  </code></pre>
  <p>That is because General does not have the function test().
  I know that I can fix this with pattern matching. This instead of the above funcForSubGeneral() works:</p>
  <pre><code>def funcForSubGeneral(): Unit =
          array(0)(0) match {
           case s: SubGeneral =&gt; s.test()
           case _ =&gt; println(&quot;nope&quot;)
          }
  </code></pre>
  <p>But I was wondering if it is possible to get the runtime type of array(0)(0) and check if it is a SubGeneral, and if that is the case then I call test(), which shouldn't cause a problem?
  That is what I was actually trying by using isIntanceOf. I want to omit pattern matching since I'm just interested in one type.</p>