【发布时间】:2021-06-30 16:12:42
【问题描述】:
我正在尝试从在同一类中返回数组的方法访问数组。然后我需要写回数组以供将来使用。这是到目前为止的代码:```
public int [] unitSelection(){
int [] selectedUnits = new int[numberCheck()];
return selectedUnits;
for (int i = 0; i < checkBoxList.length; i++) {
if (checkBoxList[i] == e.getSource()) {
index = i;
unitSelection()[i] = index;
export_to_SRF.setEnabled(true);
}
```
代码“unitSelection()[i]”应该在“unitSelected”方法中更新“selectedUnits”数组中的数组。我一直在阅读,但找不到与引用外部方法数组有关的任何内容。提前致谢
【问题讨论】:
-
我目前正在返回一个空数组
-
您得到一个空数组,因为
unitSelection()在每次调用时都会返回一个新数组。除非这只是本示例的虚拟方法体。
标签: java arrays methods reference