Jaber2599
Jaber2599

Reputation: 101

Kotlin: How to call setters and getters from java class?

So I have multiple textFields in my java class which I want to be able to get from my kotlin class to get its text and then store into a database. However, I have checked multiple sites and watched many videos, but none explicitly mention how to get a variable.

Below is my java class, how can I access and get the information inputted into these fields from a Kotlin class?

TextField projectName = new TextField();
TextField teamName = new TextField();
TextField mainTaskName = new TextField();
TextField additionalTask = new TextField();
ComboBox teamSelection = new ComboBox();
ComboBox supportSelection = new ComboBox();


public TextField getProjectName() {
    return projectName;
}

public TextField getTeamName() {
    return teamName;
}

public ComboBox getTeamSelection() {
    return teamSelection;
}

public ComboBox getSupportSelection() {
    return supportSelection;
}

public TextField getMainTaskName() {
    return mainTaskName;
}

public TextField getAdditionalTask() {
    return additionalTask;
}

Upvotes: 2

Views: 1325

Answers (1)

Marc Sances
Marc Sances

Reputation: 2614

Methods that follow the Java conventions for getters and setters (no-argument methods with names starting with get and single-argument methods with names starting with set) are represented as properties in Kotlin.

Call yourClassInstance.projectName for example.

Source: Calling Java from Kotlin

Upvotes: 2

Related Questions