Why does method1
return 1 while method2
2:
def method1 = try { 1 } finally { 2 }
def method2: Int = try { return 1 } finally { return 2 }
and why does method2
require specifying its return type?
Why does method1
return 1 while method2
2:
def method1 = try { 1 } finally { 2 }
def method2: Int = try { return 1 } finally { return 2 }
and why does method2
require specifying its return type?
This question will probably be closed by morning, but just for fun:
scala> def foo = return 1
<console>:7: error: method foo has return statement; needs result type
def foo = return 1
^
SLS 6.20: "The type of a return expression is scala.Nothing."
That answers the second question. It doesn't assist result type inference.