title: Scala: can I get access to the type of a typed method?
body: <p>I'm writing a DSL and I have a situation where'd I'd like a value to be implicitly converted to any type.  I've created a wrapper class with the value and an implicit method that mostly works:</p>
  
  <pre><code>case class ObjectOperationResult( val value: AnyRef )
  
  object ObjectOperationResult {
      implicit def result2T[ T ]( result: ObjectOperationResult ): T = {
          result.value.asInstanceOf[ T ]
      }
  }
  </code></pre>
  
  <p>The code will throw an exception if result.value isn't a valid type; it's up to the user to make sure they're doing the right thing.  However, I'd like to make it smarter by executing different logic depending on the target type.  For example, if the target type is String call toString instead of asInstanceOf[]; something like this:</p>
  
  <pre><code>case class ObjectOperationResult( val value: AnyRef )
  
  object ObjectOperationResult {
      implicit def result2T[ T ]( result: ObjectOperationResult ): T = {
          match T {
              case String s: result.value.toString
              case _ : result.value.asInstanceOf[ T ]
          }
      }
  }
  </code></pre>
  
  <p>This doesn't compile; is there any way to determine the type of T so I can act accordingly?</p>