Possible Duplicate:
Why to use empty parentheses in Scala if we can just use no parentheses to define a function which does not need any arguments?
Consider we have a class Foo
with a method bar
(which does takes no arguments and return the string "bar"
). There are two ways to implement bar
The first one is
class Foo {
def bar() = "bar"
}
The second one is
class Foo {
def bar = "bar"
}
While both do basically the same, they need to be called differently, the first one like this
someFoo.bar()
and the second one
someFoo.bar
Why should I use one over the other and what's the fundamental difference?