This question has been answered in Stack overflow before but since I am new to Kotlin I didn't understand that. It would be very helpful If someone can tell me what is wrong in the below code (In simple language) and how I can fix that. I am getting a warning from IntelliJ IDEA under 'name' property in Country class that I am trying to access non final property name in constructor. What is wrong with that?
open class Country (n : String? = null)
{
open var name : String? = n
init {
if (n==null)
{
this.name = "Unknown Country"
}
else
{
this.name = n
}
}
fun printCountryName()
{
println("Country Name : ${this.name}")
}
}
class India constructor(n: String? = null, p: Int, g: Double ): Country(n)
{
override var name : String? = "India"
}