If you use factory method in Kotlin to create an object, like:
class Person private constructor(val firstName:String , val lastName: String) {
companion object {
fun createPerson(firstName: String, lastName: String): Person {
return Person(firstName, lastName)
}
}
}
Calling factory method works:
val person1 = Person.createPerson("Niels", "Abel")
And also, of course, you can't call the constructor directly:
val person2 = Person("Évariste", "Galois")
The resultant error is: Cannot access '<init>': it is private in 'Person'
But, why they choose to report this particular error? What is <init>?