This site requires JavaScript, please enable it in your browser!
Greenfoot back
Nosson1459
Nosson1459 wrote ...

2017/2/9

Date

1
2
Nosson1459 Nosson1459

2017/2/10

#
If you say so.
davmac davmac

2017/2/10

#
Technically this code won't run any differently if it didn't have "static final" but you put it there because it could be put there. (and to get in the habit of...)
It will do something different with "static", although the end result will be the same. This is not the same as the difference between using for example public versus private, where it will not do anything different at all (as long as it compiles in both cases). If a line looks like:
private static final String[] DAYS = ...
... Then it runs once, when the class is initialised. If instead it looks like:
private final String[] DAYS = ...
... Then it runs every time you construct an instance of the class, and further each instance of the class will have its own copy of the DAYS variable. This is not just a matter of style; it is a difference in what is happening during execution, and will have an effect (however small) on execution speed and memory use.
You need to login to post a reply.
1
2