H
HK
Hi,
once in a while I have a class which is a singleton --- almost. It
means
there is a default object which does not change its inner state
at all and can be used in nearly all cases. Only for special needs
a differently parameterized object is necessary.
What I typically do, looks like this:
public class TheClass {
// provide default object to be used most of the time
public static final TheClass THECLASS = new
TheClass(some_default_param);
public TheClass(SomeParamType param) {
// create special purpose object.
}
}
The thing which annoys me is that to use the default object
I end up writing TheClass.THECLASS all over the place, which
I find a bit too verbose.
With Java 5 I can import the static object, but I wonder if
there is a more clever solution --- less verbose --- for earlier
Java versions.
Harald.
once in a while I have a class which is a singleton --- almost. It
means
there is a default object which does not change its inner state
at all and can be used in nearly all cases. Only for special needs
a differently parameterized object is necessary.
What I typically do, looks like this:
public class TheClass {
// provide default object to be used most of the time
public static final TheClass THECLASS = new
TheClass(some_default_param);
public TheClass(SomeParamType param) {
// create special purpose object.
}
}
The thing which annoys me is that to use the default object
I end up writing TheClass.THECLASS all over the place, which
I find a bit too verbose.
With Java 5 I can import the static object, but I wonder if
there is a more clever solution --- less verbose --- for earlier
Java versions.
Harald.