I have a Java class of the format:
class JavaClass {
private String name;
private Boolean x;
public String getName() { return name; }
public void setName(String name) { this.name = name }
public Boolean isX() { return x; }
public void setX(Boolean x) { this.x = x }
}
And I am overriding this class into a Data class in Kotlin, which is of the format:
data class KotlinClass(
var nameNew: String? = null,
var xNew: Boolean = false
): JavaClass() {
init {
name = nameNew
x = xNew
}
}
When I do this, the name initialization this way doesn't give a problem, but I can't initialize x in this way. The IDE complains that x is invisible. Why with x and not with name?
I created a new variable in the Kotlin class with the name x with a custom getter and setter and it complains about an accidental override for the setter (That is understandable.). This means that the the Java setter and getter is visible in the Data class. So why is the setter not being used for x in the init block, like it is doing for name?