Constructors in Kotlin

Viewed 27736

I am learning Kotlin from official docs, I created one class like below where I created one constructor which has two parameters. Body of constructor is in init block.

class Person(name: String, surname: String) {
    init {
        Log.d("App", "Hello");
    }
}

Well, I want to create one more constructor which will take one parameter in a constructor. What is the way to do in Kotlin

6 Answers

Use the variable 'internal' and then you can add multiple constructors inside single class like below.

class AuthModel {
var code: String? = null

internal constructor(code: String?) {
    this.code = code
}

internal constructor() {}
}
Related