Suppose I have the following Scala code:
class Foo(a: Int)
class Bar(b: Buffer[Int]) extends Foo (sum) {
def sum = (1 /: b)(_ + _)
}
why does it complain on calling the method sum from the constructor? Is it not possible to get such a behavior with such simple implementation at all? I realize that I could make a companion object for Bar but that is not exactlywhat would I do?
PS there is no ‘superconstructor’ tag!)))
UPDATE: What are possible alternatives?
Each time an instance of
Baris being constructed all its members are being added to it. Only after the construction is complete can you call its members.