Skip to content

Instantly share code, notes, and snippets.

@hubte1g
Forked from JoshRosen/README.md
Last active August 29, 2015 14:08
Show Gist options
  • Save hubte1g/cb56e4f4ae656643d6a3 to your computer and use it in GitHub Desktop.
Save hubte1g/cb56e4f4ae656643d6a3 to your computer and use it in GitHub Desktop.
import java.io.ObjectOutputStream
import java.io.ObjectOutputStream
import java.io.ObjectInputStream
import java.io.FileOutputStream
import java.io.FileInputStream
class A {}
class B extends A with Serializable {
def f = (a: Int) => a
}
class C(val func: Int => Int) extends Serializable { }
object D {
def main(args: Array[String]) {
if (args.size == 0) {
println("Writing object to test.bin")
val b = new B()
val c = new C(b.f)
val fs = new FileOutputStream("test.bin")
val os = new ObjectOutputStream(fs)
os.writeObject(c)
os.close()
fs.close()
}
else {
println("Reading object from test.bin")
val fs = new FileInputStream("test.bin")
val os = new ObjectInputStream(fs)
val c = os.readObject().asInstanceOf[C]
}
}
}
#!/usr/bin/env bash
if [ -z $1 ]; then
echo "Usage: $0 scalaVersion"
exit -1
fi
SCALA_VERSION=$1
echo "Testing with Scala $1"
set -x
rm test.bin
sbt "++ $SCALA_VERSION" clean compile
scala -cp target/scala-*/classes/ D
scala -cp target/scala-*/classes/ D read
rm target/scala-*/classes/A.class
scala -cp target/scala-*/classes/ D read
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment