假设案例:
public class Executor {
public static class Properties {
public final static String SOME_PROPERTY;
static {
java.util.Properties properties = PropertiesReader.readProperties();
SOME_PROPERTY = properties.getProperty("some.property");
}
}
}
这里一切都很好,代码编译。但是当我们这样改变时:
public class Executor {
public static class Properties {
public final static String SOME_PROPERTY;
static {
java.util.Properties properties = PropertiesReader.readProperties();
// The changes go here
Properties.SOME_PROPERTY = properties.getProperty("some.property");
}
}
}
由于某种原因失败,编译错误
"无法分配最终字段"
您可以通过解释第一个和第二个样本之间的区别来帮忙吗?