blob: 61c515228373c852ec6f310b22df643b93e68ca4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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]
}
}
|