Scala - parameter of type T or => T
问题 Is there any difference between the following def foo(s: String) = { ... } and def foo(s: => String) { ... } both these definitions accept "sss" as parameter. 回答1: An argument String is a by-value parameter, => String is a by-name parameter. In the first case, the string is passed in, in the second a so-called thunk which evaluates to a String whenever it is used. def stringGen: String = util.Random.nextInt().toString def byValue(s: String) = println("We have a '" + s + "' and a '" + s + "'")