In Scala in Depth there is this example:
trait Logger {
def log(category: String, msg: String) : Unit = {
println(msg)
}
}
trait DataAccess {
def query[A](in: String) : A = {
...
}
}
trait LoggedDataAccess {
val logger = new Logger
val dao = new DataAccess
def query[A](in: String) : A = {
logger.log("QUERY", in)
dao.query(in)
}
}
I am a little confused by the initialization of Logger and DataAccess in the trait LoggedDataAccess. In the REPL, when I type out this code, I get the following exception:
error: trait Logger is abstract; cannot be instantiated
val logger = new Logger
Can a trait actually be initialized like that?