简体   繁体   中英

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;
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM