我正在尝试从同一 .java 文件中的另一个函数获取变量。
这是一个例子:
public static void showWindow(User user)
{
String checkList = null;
if (user.getNetConnection().getBonus() >= 0.)
{
checkList = "variable1";
}
else
{
checkList = "variable2";
}
showCommunity(user, checkList);
}
private static void loadSingle()
{
allSingle = new LinkedList<>();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(checkList);
ResultSet rset = statement.executeQuery())...(the rest of funcion here)
无论如何,可以在函数 loadSingle 中使用函数 showWindow 中的变量 checklist 吗?
最佳答案
在方法之外声明它(我假设您的意思是 checkBuffList
)。
关于Java 在其他函数中设置和获取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31884272/