且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么设置一个静态方法导致堆栈溢出?

更新时间:2022-06-15 08:55:24

您不应该;我希望你有这样的:

You shouldn't; I expect you have something like:

private static int foo;
public static int Foo {
    get {return foo;}
    set {Foo = value;} // spot the typo!!! (should be foo)
}

从本质上讲,设置是:

static void set_Foo(int value) {
    set_Foo(value);
}

,所以这是递归的,并且最终会消耗堆栈向上(假定没有***化,等等)。

so this is recursive, and will eventually consume up the stack (assuming no optimisations, etc).

这是不可能的诊断多无一code样本。

It is impossible to diagnose more without a code sample.