英文:
Kotlin: How to call setters and getters from java class?
问题
以下是我的Java类,我想从我的Kotlin类中获取其中的文本字段,以获取其文本,然后将其存储到数据库中。但是,我已经查阅了多个网站并观看了许多视频,但没有一个明确说明如何获取变量。
以下是我的Java类,我应该如何从Kotlin类中访问并获取输入到这些字段中的信息?
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;
}
英文:
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;
}
答案1
得分: 2
遵循Java约定的获取器和设置器方法(无参数方法名称以get开头,单参数方法名称以set开头)在Kotlin中被表示为属性。
例如,调用yourClassInstance.projectName
。
来源:从Kotlin调用Java。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论