Java不允许您在函数局部内部类内定义非最终静态字段。只允许顶级类和静态嵌套类具有非最终静态字段。
如果您要
static在
Constants班级中添加一个字段,请将其放在
Application班级级别,如下所示:
public class Application { static final class Constants { public static String name = "globe"; } public static void main(String[] args) { Thread thread = new Thread(new Runnable() { @Override public void run() { System.out.println(Constants.name); } }); thread.start(); }}


