A constructor also differs from a function in that it has no body.
Instead, Kotlin uses a block of code prefixed by init
. That block of code will
be called when the object is instantiated.
There are other ways of handling the data-conversion problem shown in this sample,
such as property initializers. As a result, init
blocks are available but often
are not needed.
You can learn more about this in:
Tags: