A
Andreas Leitgeb
I'm aware that in Java, methods cannot have static data within
them. The usual "workaround" is to place static data for a
method in static fields of the class. However, I need the
static fields lexically separated for the methods.
My first thought was to write a static class named after the
method, then start the method like this:
static class static_fuBar { static int foo; static int bar; ... }
public static void fuBar(...) {
import static static_fuBar.*;
// now use foo and bar by their bare names ...
}
That of course doesn't work, either, because Java is very
restrictive about where "import static" can be used. (I added
it merely to illustrate what I'd like to arrive at.) Is there
some other trick?
PS: besides fuBar, I'll also have a couple further methods with
each's own set of effectively-static canonically-named fields, so
making foo&bar just static fields of the main class is not an option.
also renaming each foo and bar to <methodname>_foo and <methodname>_bar
isn't satisfying.
PPS: If this path of thought is really a dead end, then I'll do
the backtracking, myself, so no need asking for the broader picture.
them. The usual "workaround" is to place static data for a
method in static fields of the class. However, I need the
static fields lexically separated for the methods.
My first thought was to write a static class named after the
method, then start the method like this:
static class static_fuBar { static int foo; static int bar; ... }
public static void fuBar(...) {
import static static_fuBar.*;
// now use foo and bar by their bare names ...
}
That of course doesn't work, either, because Java is very
restrictive about where "import static" can be used. (I added
it merely to illustrate what I'd like to arrive at.) Is there
some other trick?
PS: besides fuBar, I'll also have a couple further methods with
each's own set of effectively-static canonically-named fields, so
making foo&bar just static fields of the main class is not an option.
also renaming each foo and bar to <methodname>_foo and <methodname>_bar
isn't satisfying.
PPS: If this path of thought is really a dead end, then I'll do
the backtracking, myself, so no need asking for the broader picture.