Kotlin: Installing a private Boolean Java class through the Data class in Kotlin. Why can't I do this?

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?

+6
1

- Kotlin Java- . T isSomething() ( T getSomething()), Kotlin isSomething ( something). x = xNew .

, isX:

init {
    name = nameNew
    isX = xNew
}

, isX() getX() Java-, x = xNew .

+6

All Articles