I have a Class named A that extends a Trait X. X has an abstract variable x that has been implemented in the class A. Class A uses one of the functions in Trait X named foo. I am trying to make a companion object of Class A and put in some 'static' method inside it named Ofoo. My problem is that Ofoo uses foo. So, I tried doing something like this:
trait X{ val x:String def foo = { //Full implementation here } } case class A extends X{ val x = "barbaz" // Class uses foo } object A extends X{ def Ofoo = { //This also needs to use foo } } I get an error saying the object A cannot be instantiated as the variable x is not defined in trait X. How should I structure A such that it can use the function foo defined in the trait X?