When creating an object without class parameters, I am having difficulty deciding whether I should include empty parentheses or not. A specific example: I am interfacing with existing Java code, and creating an object that implements an interface called EventResponder. Should I write:
val service = new EventResponder() {
def respond(message: String): String = {
return ""
}
}
or
val service = new EventResponder {
def respond(message: String): String = {
return ""
}
}
(Or, BTW, is there something else I should change here?)
Both seem to work, and as far as I can see, the Scala style guide does not have any recommendations for this. It talks about when to include empty parentheses for methods or arity-0, but that's not quite the same case.
def respond(message: String) = ""
EventResponder
for a parameter less class or a trait at a later time without having to go back to this code and remove the parens. That's the only tangible benefit I can see.