title: Scala: Reading a serialized object from a file
body: <p>I'd like to read a serialized object from a file in Scala, recovering functionality similar to Python's pickle. My broken object reading code looks like this:</p>
  
  <pre><code>def ReadObjectFromFile[A](filename: String): A = {
    val input = new ObjectInputStream(new FileInputStream(filename))
    val obj = input.readObject()
    obj match {
      case a: A =&gt; a
      case _ =&gt; sys.error("Type not what was expected when reading from file")
    }
  }
  </code></pre>
  
  <p>However, this code results in the warning "abstract type A in type pattern A is unchecked since it is eliminated by erasure". What is the proper way to do this?</p>