Hey guys. What is the reasoning behind using the c...
# getting-started
j
Hey guys. What is the reasoning behind using the colon (":") to call the primary constructor from a secondary constructor? In other cases the ":" colon separates the type (parameter) or return type. This seems to be a little bit inconsistent for me (as a Java dev). Any explanation for that?
k
Well I tend to think of the : operator as meaning "has a type of". In classes that is interpreted as "is a subtype of", and if the parent class needs arguments that's where you specify them too. With val en var it specifies it's type, and it also specifies the type you get from calling that method.
j
Yeah. This make sense in most cases. But in the case of a constructor? "Secondary constructor is type of primary constructor"? Don't know about that...
k
Well it does, the (return) type of this constructor is a subtype of the parent constructor's (return) type.