3 回答
TA贡献1811条经验 获得超6个赞
Int
.
def something() = { println("calling something") 1 // return value}
Int
x: Int
x: => Int
).
def callByValue(x: Int) = { println("x1=" + x) println("x2=" + x)}def callByName(x: => Int) = { println("x1=" + x) println("x2=" + x)}
scala> callByValue(something())calling something x1=1x2=1scala> callByName(something())calling something x1=1calling something x2=1
something()
TA贡献1835条经验 获得超7个赞
def test (x:Int, y: Int)= x*x
test (2,3)
test (3+4,8)
test (7,2*4)
test (3+4, 2*4)
TA贡献1880条经验 获得超4个赞
def callByName(x: => Int) = { println("x1=" + x) println("x2=" + x)}
scala> callByName(something())calling something x1=1calling something x2=1
def callAlsoByName(x: () => Int) = { println("x1=" + x()) println("x2=" + x())}
callAlsoByName(() => {something()})calling something x1=1calling something x2=1
- 3 回答
- 0 关注
- 556 浏览
添加回答
举报