Java 用另一个函数返回布尔函数
我想知道怎么做 比如说,我有一个函数Java 用另一个函数返回布尔函数,java,function,boolean,Java,Function,Boolean,我想知道怎么做 比如说,我有一个函数 public boolean function() { // many if statements here // functionReturn(); after each statement } public void functionReturn() { if(isMade) { return true; (for function) I need this to return the FUNCTION() true } return fa
public boolean function() {
// many if statements here
// functionReturn(); after each statement
}
public void functionReturn() {
if(isMade) {
return true; (for function) I need this to return the FUNCTION() true
}
return false; (for function) I need this to return the FUNCTION() false
}
基本上,我的function()布尔函数必须由另一个函数返回,因为function()中有很多代码-我不想重复代码,这就是为什么我想使用returnRawr()使它更清晰、更好
isMade是一个公共布尔变量
欢迎提供任何提示,如果这是一个愚蠢的问题,很抱歉。方法不能返回任何返回类型为void
的内容。
请小心操作,否则将导致堆栈溢出错误
,如下面的示例代码所示
public boolean function() {
return functionReturn();
}
public boolean functionReturn() {
return function();
}
我想你想做这样的事情:
public boolean function() {
//many if statements here
return functionReturn();
}
public boolean functionReturn() {
return isMade;
}
它的要点是返回functionReturn()返回的值。functionReturn()返回isMade的值
但你的问题很不清楚。我觉得这不是你想要的,因为你可能只需要返回
isMade
insidefunction()
那么我该怎么做呢?是的,但如果我这样做,它将返回functionReturn()false或true,我需要functionReturn返回“main”函数()正确或错误如果您显示函数的示例
,则会有所帮助。特别是,您是否只想在某些情况下返回?你的问题目前还不清楚。一个完整的例子——即使只是相当简单——将非常有用。