Using scala constructor to set variable defined in trait

trait Foo { var foo: String = _ }
class Bar(foo0: String) extends Foo { foo = foo0 }

The trait declares an uninitialized var; the class then sets it equal to the input parameter.

Alternatively,

trait Foo {
  def foo: String
  def foo_=(s: String): Unit
}
class Bar(var foo: String) extends Foo {}

declares the getter/setter pair corresponding to a foo, which are set by the class.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)