java - 如何让两个函数相互调用 Java

标签 java forward-declaration

我知道我们在 C++ 中这样做是这样的:

int a();
int b() { 
  return a();
}
int a() { 
  return b();
}

我如何在 Java 中做这样的事情?

最佳答案

在 Java 中,您不必在使用变量或函数之前声明它们。因此:

int b() { return a();}
int a() { return b();}

请注意,这将产生一个 StackOverflowError

关于java - 如何让两个函数相互调用 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20121911/

相关文章:

java - 如何使用 RestTemplate 进行 GSM 编码

C++ 语法有问题,所以一个类可以将数据传递给其他类

c++ - 带有友元函数的前向声明 : invalid use of incomplete type

c++ - 错误 : Invalid use of incomplete type struct Subject; error: forward declaration of struct Subject

java - 比较java中的字符串并删除字符串中相同的部分

创建 BoxLayout 时的 java.awt.AWTERROR

java - @StepScope 是否可以与 @Conditional 和 jobParameters 一起使用?

java - 在 JLabel 扩展类中找不到符号

c++ - C++ 中 typedef 的前向声明

c++ - 我如何转发声明一个类并稍后在 C++ 中使用它的成员函数?