Assume the case:
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");
}
}
}
Here all is fine and code compiles. But when we change it this way:
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");
}
}
}
It's for some reason fails, with compilation error that
"final field could not be assigned"
Could you please help by explaining the difference between first and second sample?