mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Scala compiler fails to infer the return type when there's an explicit return statement
This commit is contained in:
parent
fe856e7117
commit
6027c90c90
@ -199,7 +199,7 @@ weirdSum(2, 4) // => 16
|
|||||||
|
|
||||||
// The return keyword exists in Scala, but it only returns from the inner-most
|
// The return keyword exists in Scala, but it only returns from the inner-most
|
||||||
// def that surrounds it. It has no effect on anonymous functions. For example:
|
// def that surrounds it. It has no effect on anonymous functions. For example:
|
||||||
def foo(x: Int) = {
|
def foo(x: Int): Int = {
|
||||||
val anonFunc: Int => Int = { z =>
|
val anonFunc: Int => Int = { z =>
|
||||||
if (z > 5)
|
if (z > 5)
|
||||||
return z // This line makes z the return value of foo!
|
return z // This line makes z the return value of foo!
|
||||||
|
Loading…
Reference in New Issue
Block a user