语法的省略不能造成编译器的歧义
时间:2014-04-29 22:15:21
收藏:0
阅读:500
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]; } } |
评论(0)