While you can certainly implement greet
, as noted by @chris, that code snippet overloads Foo.greet(name:String)
; it does not override it:
class Greeter extends Foo with Bar {
def greet = hello _
}
<console>:9: error: class Greeter needs to be abstract, since method
greet in trait Foo of type (name: String)String is not defined
class Greeter extends Foo with Bar { def greet = hello _ }
While the following does compile:
class Greeter extends Foo with Bar {
def greet(name: String) = hello(name)
def greet = hello _
}
As an aside, you can also define greet
with an explicit type decl, without the trailing underscore:
def greet: String=> String = hello