Monday, 30 July 2007

 

Final static fields can be initialised in static initialiser

Continuing my list of Things that I still discover about Java I anticipate a loud "feeww" from most of you java programmers. I nevertheless confess that I never used it before and just now discovered that it is at all possible. That is, just as final instance fields can be initialised in the constructor (which I use a lot), static final fields can be initialised in the static intialiser, a "static class constructor". I really like this language feature as it adds compiler checks on potential encapsulation violations:
private final static File someFile;
static {
someFile = ...;
}

Labels: , ,


Comments:
Hello, Lesha.

I do like this code:

main()
{
printf("%s", "Hello, world");
}

:)

Didn't know what to add as a comment, so decided to participate in the writing in this bizzare manner :)

Rustam.
 
Look, you've made a comment! Good boy, well done!
 
Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom], Comments [Atom]