That was amazingly well explained
Here are my thoughts on statics and finals..
- making something static, and especially static final will speed up things, I have proven this (in J2ME atleast) - due to the less checking required during run time, ie, no checking at all if its final - I guess the compiler does some nice jiggery pokery also since its a "constant" effectively if its final. Even though I could get burned at the steak for suggesting this, when I need to optimise, I make everything static and static final if I can - SO LONG AS THIS WILL NOT AFFECT anything in my run time - ie, you know that there is only ever once instance of a class.
- the same approach can save jar size and make life easier, again heretic speak but I often cant be bothered to code a getVal() setVal() so I just make it public static and get it by doing ClassName.myStaticVar - it is a hell of a lot quicker than making get/set methods or even trying to find the instance name and doing instance.myVar. Again ONLY IF THIS WONT AFFECT the runtime of my code. You may argue this is bad practise for later when I upgrade my code, yep thats fair enough.
- As Jo mentioned statics should be done in capital letters, mainly so your brain goes ohh CAPS must be static (im learning all these conventions are really clever because you save so much time not checking what stuff is - similarly if you keep all your variables named the same sort of thign throughout your career in the end youll be able to "guess" what you called it without going looking) - using these finals in things that get called a lot can speed things up, like in a constantly called draw method:
getWidth()/3.142
is blatently going to be slower than:
WIDTH/PI
or even:
WIDTH_OVER_PI (fastest)
in switch statements its nice do use finals, as the states will enver change, ie:
switch(gameMode)
{
case INTRO:
break
case CREDITS:
}
which helps code readability..
Anyway just thought id stick my 2 cents in there in case it helps.. I have a tendency to tell people stuff how it is, rather than the academic way and sometimes I feel "human beings" prefer it that way
Thats not to say Jo is not a human being, I loved the explanations, Im just talking about these Java purists who would have me hanged for saying yeh I make stuff static final for speed and ease... (mostly theyre hiding on IRC
Cheers,
Gaz.