I have a Java class of 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 redefine this class to the Data class in Kotlin, which has the format:
data class KotlinClass(
var nameNew: String? = null,
var xNew: Boolean = false
): JavaClass() {
init {
name = nameNew
x = xNew
}
}
When I do this, initializing the name in this way does not give a problem, but I cannot initialize x in this way. The IDE complains that x is invisible. Why with x and not with a name?
I created a new variable in the Kotlin class named x with a custom getter and setter, and it complains about a random override for setter (this is understandable). This means that the Java installer and getter are visible in the Data class. So, why is the setter not used for x in the init block, as it does for the name?