我有以下方法
public Object[] loopthroughTables(){
Object[] tables = new Object[1];
tables[0] = tableR;
tables[1] = tableB15;
return tables;
}
我想从我的调用方法中检索 tableR
loopthroughTables();
我当前的设置是
Object[][] data = getTableData(tableR); //create an array of the table data
但我想做一些类似的事情
Object[][] data = getTableData(loopthroughTables()); //create an array of the table data
我该怎么做?
最佳答案
使用loopthroughTables()
作为数组引用。
Object tableR = loopthroughTables()[0];
另一种方法是将方法返回类型更改为 Object
并返回 tableR
警告
new Object[1] 创建一个新的 Object
数组,该数组只能包含一个且唯一的 Object
对象。因此,您的代码将在运行时抛出 Exception
,因为 tables[1] = tableB15;
关于java - 仅检索一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37368180/