title: Calling a fun with reified type parameter if you just have a KClass object?
body: <p>One can only use reified type parameters with inline functions. So if I want such a parameter for a class I need a trick like this:</p>
  
  <pre><code>class Foo&lt;T : Any&gt;(private val clazz: KClass&lt;T&gt;) {
      companion object {
          inline fun &lt;reified T: Any&gt; create() = Foo(T::class)
      }
  }
  </code></pre>
  
  <p>I can then create instances of <code>Foo</code> like this:</p>
  
  <pre><code>val foo = Foo.create&lt;Bar&gt;()
  </code></pre>
  
  <p>Within <code>Foo</code> I have access <code>clazz</code> but my question is <strong>can I then use <code>clazz</code> when I need to call methods that require a reified type parameter`</strong>?</p>
  
  <p>E.g. within <code>Foo</code> I'd like to add a method like this:</p>
  
  <pre><code>fun print(list: List&lt;Alpha&gt;) {
      list.filterIsInstance&lt;T&gt;().forEach { print(it) }
  }
  </code></pre>
  
  <p>But as far as I can see there's no way to get from <code>clazz</code> to something I can use as a type parameter here.</p>
  
  <p>And yes, I know there's a form of <code>filterIsInstance</code> that takes a <code>Class</code> so I can do:</p>
  
  <pre><code>list.filterIsInstance(clazz.java).forEach { print(it) }
  </code></pre>
  
  <p>However many libraries contain methods where both forms (explicit class parameter and reified type parameter) are <em>not</em> provided.</p>
  
  <p>E.g. the Jackson Kotlin <a href="https://github.com/FasterXML/jackson-module-kotlin/blob/master/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt" rel="noreferrer">Extensions.kt</a>. Actually this isn't a great example as the non-reified equivalents are all one-liners but this isn't always the case - then you end up unpacking the implementation of the reified-type-parameter method into your code.</p>