Why does Kotlin have two types of constructors?
Why does Kotlin have two types of constructors? 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. 2 Answers 2 Primary constructors cover the poplular use case when you need to save the values passed as the constructor arguments to the properties of the instance. Basically, a primary constructor provides a shorthand for both declaring a property and initializing it from the constructor parameter. Note that you can do the same without primary constructors at all: class Foo { val bar: Bar constructor(barValue: Bar) { bar = barValue } } But, since this happens really often in the codebases, K...