3 回答

TA貢獻1811條經(jīng)驗 獲得超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條經(jīng)驗 獲得超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條經(jīng)驗 獲得超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 關(guān)注
- 612 瀏覽
添加回答
舉報