Java中的形式参数和显式参数是否相同?
Are formal parameters and explicit parameters the same in Java?
我知道显式参数是那些列在方法调用括号内的参数。我也知道形参就是方法标题中的参数名称。
在这段代码中,调用 x 既是形式参数又是显式参数有意义吗?
public int add(int x, int y) {
return x + y;
}
如果是这样,在任何情况下您都会有一个不是显式参数的形式参数吗?
我正在尝试考虑所有可能的情况——正式显式、正式隐式、实际显式和实际隐式。所有这些都可能且有效吗?
不确定,但我认为这是正确的:
In this code, does it make sense to call x both an formal and explicit parameter?
是的,既正式又明确。
is there any case where you would have a formal parameter that is not an explicit parameter?
this
是形式隐式参数。
我们已经解决了它们是显式和隐式的问题,当您实际调用代码时它们将是实际的。
add(1,2); // 1 and 2 are actual explicit parameters
"a".length(); // "a" is the actual implicit parameter
我知道显式参数是那些列在方法调用括号内的参数。我也知道形参就是方法标题中的参数名称。
在这段代码中,调用 x 既是形式参数又是显式参数有意义吗?
public int add(int x, int y) {
return x + y;
}
如果是这样,在任何情况下您都会有一个不是显式参数的形式参数吗?
我正在尝试考虑所有可能的情况——正式显式、正式隐式、实际显式和实际隐式。所有这些都可能且有效吗?
不确定,但我认为这是正确的:
In this code, does it make sense to call x both an formal and explicit parameter?
是的,既正式又明确。
is there any case where you would have a formal parameter that is not an explicit parameter?
this
是形式隐式参数。
我们已经解决了它们是显式和隐式的问题,当您实际调用代码时它们将是实际的。
add(1,2); // 1 and 2 are actual explicit parameters
"a".length(); // "a" is the actual implicit parameter