Scala Notes — Function Return Types

scala> def func1(x: Int) = if (x > 1) x else falsefunc1: (x: Int)AnyVal
Scala> def func1(x: Int): Int = if (x > 1) x else false<console>:11: error: type mismatch;found   : Boolean(false)required: Intdef func1(x: Int): Int = if (x > 1) x else false                                           ^
scala> def func1(x: Int): Int = println(x)<console>:11: error: type mismatch;found   : Unitrequired: Intdef func1(x: Int): Int = println(x)                                ^

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store