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
karelpeeters
07/01/2017, 11:48 AM
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
jschneider
07/01/2017, 1:11 PM
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
karelpeeters
07/01/2017, 4:57 PM
Well it does, the (return) type of this constructor is a subtype of the parent constructor's (return) type.