title: Get Java reflection representation of Scala type
body: <p>This seems like a simple question, but it's very challenging to search for, so I'm asking a new question. My apologies if it's already been asked. </p>
  
  <p>Due to the compiler bug described here <a href="https://stackoverflow.com/questions/28510867/scala-2-11-5-compiler-crash-with-type-aliases-and-manifests">Scala 2.11.5 compiler crash with type aliases and manifests</a> (also here <a href="https://issues.scala-lang.org/browse/SI-9155" rel="nofollow noreferrer">https://issues.scala-lang.org/browse/SI-9155</a>), I need to use scala <code>TypeTag</code>s and friends for discovery of type parameters to methods. However, I then need to use that type information in a Java library that uses <code>java.lang.Class</code> and <code>java.lang.reflect.Type</code>.</p>
  
  <p>How can I convert a <code>scala.reflect.runtime.universe</code> <code>Type</code> into a <code>java.lang.reflect.Type</code> or <code>java.lang.Class</code>?</p>
  
  <p>Put concretely, how would I fill out the body of this method:</p>
  
  <pre><code>def typeFor[T](implicit tag: TypeTag[T]): java.lang.reflect.Type = ...
  </code></pre>
  
  <p>or, if that's not possible:</p>
  
  <pre><code>def typeFor[T](implicit tag: TypeTag[T]): java.lang.Class[T] = ...
  </code></pre>
  
  <p>And note, due to the bug posted above, I cannot use <code>scala.reflect.Manifest</code>.</p>