仅在非静态实例中发生StackOverflowError错误

时间:2018-08-18 14:25:08

标签: java object reference

class Sample {

Sample s = new Sample();
static Sample sa = new Sample();

void check(Sample s) {
    System.out.println(this.s == s);
   }
}

public class Other 
 {  Other o=new Other();//line 27
    static  Other ot=new Other();
    public static void main(String[] args) {
    new Sample().check(new Sample().s);
    }
 }

输出: java.lang.StackOverflowError

在oca.Other。(Other.java:27)

在oca.Other。(Other.java:27)

在oca.Other。(Other.java:27)

在oca.Other。(Other.java:27)

在oca.Other。(Other.java:27)

谁能解释我为什么仅在非静态实例中发生错误?

0 个答案:

没有答案