Kotlin has two types of constructors, primary and secondary. What is the purpose of having two types? In my opinion it makes the code more complicated and inconsistent. If both types of constructors create objects of a class, they are equally important to a class.
Meanwhile, multiple initialisers also introduce confusion and reduce readability.
Primary constructor can define what parameters are passed into the
init
blocks. For example:Without explicit primary constructor call it would be impossible to determine what value/type of
a
should be used ininit
.Primary constructor and initializer blocks always execute before secondary constructor block (doc).