标签:com blog class div code log string c tab ble int
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 |
package
exp { object Main { def
main(args: Array[String]): Unit = { B[String].say( "hello" ); //B[String]后的括号可以省略,编译器知道这不是要用类型B而是要调用B.apply[String] A().say( "hello" ); //括号省略了不知道是要用object的类型A还是A.apply() } } class
A { def
say(x:String) = println (x); } object A { def
apply():A = new
A; } class
B[T] { def
say(x:T) = println (x); } object B { def
apply[T]():B[T] = new
B[T]; } } |
语法的省略不能造成编译器的歧义,码迷,mamicode.com
标签:com blog class div code log string c tab ble int
原文地址:http://www.cnblogs.com/scala/p/3697005.html