I have created abstract class and trait
abstract class Person(val name: String){
val tax: Double;
}
trait Employee {
var salary: Double;
val tax: Double = salary * 0.3;
}
and I want to create an instance of class object
val examplePerson = new Person("John") with Employee;
I get Erorr
Description Resource Path Location Type object creation impossible, since variable salaryin trait Emplyee of type Double is not defined (Note that variables need to be initialized to be defined) Scala Problem
But i don't know how to set field salary with constructor while initializing. Is it possible?
When I tried setting a default value
var salary: Double = 0.0;
and then use a setter on examplePerson instance, tax is not changing becouse is immutable (it must be val).
val examplePerson = new Person("John") with Employee { override final val salary: Double = ??? }Or, consider rethinking your design.