public void method3() {
method4();
}
public void method4() {
step++;
for (StackTraceElement element : Thread.currentThread().getStackTrace())
System.out.println(element);
if (step > 1)
return;
main(null);
}
谁能帮帮我!为什么metho4()不需要static? please help me! Why method4 don't need static?
已解决
评论 (4)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
ppp122
2 七月 2020, 15:10解决方法
因为method3是非静态方法,非静态方法可以调用非静态方法,所以method4可以是非静态的。事实上我感觉step也可以是非静态的,并且把step设置成非静态程序也可以运行。但是step>1才会返回,如果step是非静态的,每个对象的step是独立的,程序会无限循环
+7
Khalil Chen
7 七月 2020, 04:44
十分感谢!
0
Khalil Chen
1 六月 2020, 08:51
各位大佬看一看。。。为什么在method3中没有实例化就能调用method4方法但是method4不需要关键字static来预加载。。。
0
Xu Yang
30 六月 2020, 15:46
同问!
0