Is there a difference between the two following..
scala> def foo() = {}
foo: ()Unit
scala> def foo() {}
foo: ()Unit
They seem to be the same.
Is there a reason both are supported?
Is there a difference between the two following..
scala> def foo() = {}
foo: ()Unit
scala> def foo() {}
foo: ()Unit
They seem to be the same.
Is there a reason both are supported?
def foo() {}
is equivalent to (and enforces)
def foo(): Unit = {}
while
def foo() = {}
will apply type infering to determine the result type from the body of the method.
So, with the first two options, Unit
is the only allowed return type, while in the third, the return type depends on the implementation.