Monday, 10 September 2007
Every time I change job I always tend to spend too much time remembering how to search for "pre-1.4 style" custom exceptions that try to store their root causes in a field. So here is the IDEA custom template for that:
Variables $Parent$ and $Throwable$ should be constrained with "text/regular expression" set to "Throwable" and "apply within type hierarchy" checkbox checked.
class $Class$ extends $Parent$ {
$Throwable$ $varName$;
}
Variables $Parent$ and $Throwable$ should be constrained with "text/regular expression" set to "Throwable" and "apply within type hierarchy" checkbox checked.
Labels: exception, idea, java, pattern
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: java, programming, software