I know that once a final variable has a value assigned to it, it cannot be changed. However I just have a couple of questions regarding this:
When I have a
You should initialize a static final variable either in a static initializer, or directly. So either
static final JButton button = new JButton();
or
static final JButton button;
static {
button = new JButton();
}
The Java language specification has some more documentation about it: the section about final variables specifies why you get the compile error:
It is a compile-time error if a final variable is assigned to unless it is definitely unassigned (§16) immediately prior to the assignment.
and chapter 16 talks about the definite assignment