这似乎是一个愚蠢的问题,但是此函数是否会实际影响变量bool(我将如何使用此变量的上下文更大,但这基本上是我不确定的问题)?(我专门问有关java)
bool
void truifier (boolean bool) { if (bool == false) { bool = true; } }
考虑一个稍微不同的示例:
public class Test { public static void main(String[] args) { boolean in = false; truifier(in); System.out.println("in is " + in); } public static void truifier (boolean bool) { if (bool == false) { bool = true; } System.out.println("bool is " + bool); } }
运行该程序的输出为:
bool is true in is false
该bool变量将更改为true,但是一旦truifier方法返回,该参数变量就会消失(这就是人们所说的“超出范围”的意思)。但是,in传递给truifier方法的变量保持不变。
truifier
in