例如,假设我有这 3 个重载函数:
/** Function #1 */
public static String add(List<String> operands)
{
return add(operands, 10);
}
/** Function #2 */
public static String add(List<String> operands, int base)
{
return Integer.toString(add(Integer.parseInt(operands.remove(0), base),operands, base), base);
}
/** Function #3 */
private static int add(int result, List<String> operands, int base)
{
if(operands.size() == 0)
{
return result;
}
result += Integer.parseInt(operands.remove(0), base);
return add(result, operands, base);
}
在这种情况下,调用函数 #2 是函数 #1 的“父”重载函数是否正确,因为函数 #1 调用它并且两者都是公共(public)的?
将函数 #3 称为这些函数的“递归”函数是否也是正确的,或者是否有另一个术语来描述它被公共(public)函数调用为递归调用自身的隐藏函数这一事实?
我知道这些不是正确的术语,但我想要了解的是,考虑到不同类型的重载函数的作用,是否有固定的术语。
最佳答案
我不愿意定义 Java 语言规范未定义的任何术语。
简单地说,您有 3 个函数,2 个 public
和 1 个 private
。它们具有相同的名称,但参数类型不同,因此它们重载。
事实上,调用自身的函数是一个递归函数。 JLS 确实定义了该术语,因为 Java 编译器必须支持调用自身的函数。
不要将您的函数之一称为“父重载” - 这并不是特别有帮助,而且您对术语“抽象”的使用很特殊。
关于java - 函数重载: Terminology for different types of overloaded functions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39535094/