In fact, Array(s) is evaluated at runtime because the structure you use is an efficient call to the main constructor of your superclass.
Recall that a class can only have a primary constructor that takes arguments in its definition of class A(param:AnyRef) , other constructors are called this and have the mandate to call the primary constructor (or bind constructors before it).
And such a restriction exists for super calls, i.e. the primary constructor of the subclass calls the super primary constructor.
Here's how to see such a Scala structure
class Foo (val x: Int) class Bar (x: Int, y: Int) extends Foo(x + y)
Java mapping
public class Foo { private x:int; public Foo(x:int) { this.x = x; } public int getX() { return x; } } public class Bar { private y:int; public Bar(x:int, y:int) { super(x+y); this.y = y; } public int getY() { return y; } }
source share