以下单例类工作正常,
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.为什么是这样?
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |