Others explained the differences between the various ads perfectly:
def foo: Boolean = true // explicitly declare the return type
and
def foo = true
Having said that, I must warn you against
def foo { }
This is called procedural syntax, and you should never use it because it has already been deprecated (since October 29, 2013), although you will get an obsolescence warning only with the -Xfuture flag.
Whenever you have to declare a method that returns Unit (which should be avoided as much as possible, as this means you rely on side effects), use the following syntax
def foo: Unit = { }
Also, as a personal tip, explicitly annotating the return types makes your code more readable and helps you quickly spot errors. You know that a function should return, so explicit type annotation allows the compiler to verify that the implementation returns the corresponding value, right at the declaration position (if you use this function, you will end up catching the error, but maybe far from where the error is really is).
Also, when declaring an abstract element, you'd better comment on the types as well
trait { def foo }
is legal, but the type foo automatically detected as Unit , which you almost never need.
Instead do
trait { def foo: Boolean }
source share