blob: 3af3ad774da127ec08b3b8a216c6eeef9a7d7cec (
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
|
Type in expressions to have them evaluated.
Type :help for more information.
scala> class X {
def methodIntIntInt(x: Int, y: Int) = x+y
}
defined class X
scala>
scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._
scala> import scala.reflect.runtime.{ currentMirror => cm }
import scala.reflect.runtime.{currentMirror=>cm}
scala> def im: InstanceMirror = cm.reflect(new X)
im: reflect.runtime.universe.InstanceMirror
scala> val cs: ClassSymbol = im.symbol
cs: reflect.runtime.universe.ClassSymbol = class X
scala> val ts: Type = cs.typeSignature
ts: reflect.runtime.universe.Type =
scala.AnyRef {
def <init>(): X
def methodIntIntInt(x: scala.Int,y: scala.Int): scala.Int
}
scala> val ms: MethodSymbol = ts.declaration(TermName("methodIntIntInt")).asMethod
ms: reflect.runtime.universe.MethodSymbol = method methodIntIntInt
scala> val MethodType( _, t1 ) = ms.typeSignature
t1: reflect.runtime.universe.Type = scala.Int
scala> val t2 = typeOf[scala.Int]
t2: reflect.runtime.universe.Type = Int
scala> t1 == t2
res0: Boolean = false
scala> t1 =:= t2
res1: Boolean = true
scala> t1 <:< t2
res2: Boolean = true
scala> t2 <:< t1
res3: Boolean = true
scala>
|