diff options
author | michelou <michelou@epfl.ch> | 2008-05-02 12:28:13 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2008-05-02 12:28:13 +0000 |
commit | 1d4fbeece9236ac84a7f77e36cf558567a4c3509 (patch) | |
tree | cb3d4ed791e5e15dde323d9fb7bb51fd89c7701c /test/files/jvm/manifests.scala | |
parent | 0f6f62e5038e9982897158c5ac25bc049683f452 (diff) | |
download | scala-1d4fbeece9236ac84a7f77e36cf558567a4c3509.tar.gz scala-1d4fbeece9236ac84a7f77e36cf558567a4c3509.tar.bz2 scala-1d4fbeece9236ac84a7f77e36cf558567a4c3509.zip |
made manifests serializable
Diffstat (limited to 'test/files/jvm/manifests.scala')
-rw-r--r-- | test/files/jvm/manifests.scala | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/files/jvm/manifests.scala b/test/files/jvm/manifests.scala new file mode 100644 index 0000000000..61c5152283 --- /dev/null +++ b/test/files/jvm/manifests.scala @@ -0,0 +1,61 @@ +object Test extends Application { + import scala.reflect._ + + def manifestOf[T](implicit m: Manifest[T]): Manifest[T] = m + + def print[T](x: T)(implicit m: Manifest[T]) { + val m1: Manifest[T] = Serialize.read(Serialize.write(m)) + val x1 = x.toString.replaceAll("@[0-9a-z]+$", "") + println("x="+x1+", m="+m1) + } + print(()) + print(true) + print('a') + print(1) + print("abc") + + print(List(())) + print(List(true)) + print(List(1)) + print(List("abc")) + + //print(Array(())) //Illegal class name "[V" in class file Test$ + print(Array(true)) + print(Array('a')) + print(Array(1)) + print(Array("abc")) + + print(((), ())) + print((true, false)) + print((1, 2)) + print(("abc", "xyz")) + + print(Serialize) + print(Test) + print(List) + + class Foo[T](x: T) + print(new Foo(2)) + print(new Foo(List(2))) + print(new Foo(new Foo(2))) + print(new Foo(List(new Foo(2)))) + + trait Bar[T] { def f: T } + print(new Bar[String] { def f = "abc" }) +} + +object Serialize { + import java.io._ + def write[A](o: A): Array[Byte] = { + val ba = new ByteArrayOutputStream(512) + val out = new ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + def read[A](buffer: Array[Byte]): A = { + val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } +} + |