是什么导致java.lang.StackOverflowError [英] What causes a java.lang.StackOverflowError

查看:158
本文介绍了是什么导致java.lang.StackOverflowError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么会导致java.lang.StackOverflowError?我得到的堆栈打印输出根本不是很深(只有5种方法).

What can cause a java.lang.StackOverflowError? The stack printout that I get is not very deep at all (only 5 methods).

推荐答案

检查对方法的任何回溯调用.主要是在递归调用方法时引起的.一个简单的例子是

Check for any recusive calls for methods. Mainly it is caused when there is recursive call for a method. A simple example is

public static void main(String... args) {
    Main main = new Main();

    main.testMethod(1);
}

public void testMethod(int i) {
    testMethod(i);

    System.out.println(i);
}

这里是System.out.println(i);调用testMethod时将被反复推入堆栈.

Here the System.out.println(i); will be repeatedly pushed to stack when the testMethod is called.

这篇关于是什么导致java.lang.StackOverflowError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆