我有一个代码:
package why;
public class Foo
{
public class Foo1
{
String bar;
public Foo1(String bar)
{
this.bar = bar;
}
public static Foo1 MYCONSTANT = new Foo(null);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我得到'非静态变量,这不能从静态上下文引用'?我分配了非静态类的实例.
为什么在这里?
public static Foo getMYCONSTANT()
{
return new Foo(null, null);
}
Run Code Online (Sandbox Code Playgroud)
谢谢