I have a trait definition:
trait T {
def name: String
}
I can create an object like:
val o = new {
val name: String = "anonymous"
} with T
But I cannot create the object in the following way:
val o = new {
def name: String = "anonymous"
} with T
The compiler said ';' or newline expected in line } with T
. The only different is I used def
instead of val
in the second implementation.
I know that method can be defined in an anonymous object, but why I cannot use in this way here?