使用"this"与不在Java的单例类中使用它?

Kob*_*obi 1 java

以下单例类工作正常,

public class Elvis
{
    private static Elvis elvis = new Elvis();

    private Elvis()
    {

    }

    public static Elvis Instance()
    {
        return elvis;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我换return elvis;到时return this.elvis,我明白了non-static variable this cannot be referenced from a static context.为什么是这样?

Jef*_*rey 11

this指的是当前的对象实例.甲static方法不包含在一个对象,它是由类含有.