标签: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 | packageexp {    object Main {        defmain(args: Array[String]): Unit = {             B[String].say("hello"); //B[String]后的括号可以省略,编译器知道这不是要用类型B而是要调用B.apply[String]             A().say("hello"); //括号省略了不知道是要用object的类型A还是A.apply()        }    }    classA    {        defsay(x:String) = println(x);    }    object A    {        defapply():A = newA;    }    classB[T]    {        defsay(x:T) = println(x);    }    object B    {        defapply[T]():B[T] = newB[T];    }} | 
语法的省略不能造成编译器的歧义,码迷,mamicode.com
标签:com blog class div code log string c tab ble int
原文地址:http://www.cnblogs.com/scala/p/3697005.html