i'm trying understand syntax inheriting 1 class , seems must announce constructor parameters of parent when create child?
why code not compile?
class animal(name:string) class dog extends animal //here compiler error occurs
but does
class animal(name:string) class dog(name:string ) extends animal(name)
is reason must explicitly extends animal(name)
, not extends animal
, constructor implied?
the scala language specification doesn't (as far can see) discuss reasons, providing implied constructor special case, , arguably less clear.
note can things like:
class animal(name:string) class dog extends animal("dog")
and
class animal(name:string) class dog(n1: string, n2: string) extends animal(n1 + n2)
so current behaviour accommodates variety of patterns in uniform , explicit way.
Comments
Post a Comment