title: How to get the type and the size of the type from T?
body: <p>How can I get the type and the size of the type from T?
  For example, when I'm trying to convert Integer or Long to ByteArray using generics in Scala, how can I get the type information from T?</p>
  
  <pre><code>def dataToByteArray[T](x: T) = {
    if T is IntType
      ByteBuffer.allocate(4).putInt(x).array()
    else if T is LongType
      ByteBuffer.allocate(8).putLong(x).array()
    else
      raise an error
  }
  </code></pre>
  
  <p>I may use polymorphic functions, but I'm curious how scala can give the type info. </p>
  
  <pre><code>def dataToByteArray(x: Int) = {
    ByteBuffer.allocate(4).putInt(x).array()
  }
  def dataToByteArray(x: Long) = {
    ByteBuffer.allocate(8).putLong(x).array()
  }
  </code></pre>