Reputation: 1916
i have a question about scala and logic in constructor. Lets say i have a following code:
class A(val x:Int) {...whatever...}
class B(val y:String) extends A(IntValueDerivedFrom_y)
Now, how would i derive some value from y and passed it to constructor of class A? I hope it's understandable what i ask about.
Thanks for the answers!
Upvotes: 2
Views: 381
Reputation: 29528
Not sure I understand. You may do
class B(val y: String) extends A(f(y))
f(y)
stands for any expression where y
appears. For instance, Integer.parseInt(y)
This is close to java code
class B extends A {
public B(String y) {
super(Integer.parseInt(y));
}
}
Is that what you wanted?
Upvotes: 4