Re: Class.getMethod in class's static initializer block



Thank you for your prompt reply and elegant solution!

A couple of suggestions. One, is there something you could use that
isn't a string? int perhaps, or enum?

I think not, because that string comes from the 'outside
world' (viewed from my perspective). I was given someone else's code
that I'll have to deal with. I don't have access to this code at the
moment, I just remember that I wanted to think this out.
I'm almost sure that the application could be refactored so that it
uses enum instead of string, but that is behind my scope.


public class MyClass {
SomethingLookup lookup;
/* Iniitalize lookup in constructor */

I would still use
static SomethingLookup lookup;
and initialize it in static initializer block instead of constructor,
so that it is initialized once and not once per instance of MyClass.
Maybe you are discussing something related in the last paragraph,
which I didn't really catch on:( :

You're Something implementations can be Fly Weights, so you can pass
any state information into the methods as another class. That way you
don't have to keep different SomethingLookup and Something objects for
every object that you wish to affect.


.



Relevant Pages

  • Re: enums: What the H? again
    ... > find no sign of it in the Enum class until I did a decompile and saw ... > private String shortName; ... > private static InDir currentState = UNKNOWN; ...
    (comp.lang.java.programmer)
  • Re: enums: What the H? again
    ... Everything comes clear when you decompile an enum, ... private String shortName; ... private static InDir currentState = UNKNOWN; ...
    (comp.lang.java.programmer)
  • A Class to get the name of Enum constant at runtime
    ... Dim rs As ADODB.Recordset ... You can get the description of an Enum form it's value. ... EnumName As String, ... Dim Idx As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Record type flushing
    ... If you try to assign a new value to a string field in that ... reference, so the compiler's code tries to release that reference before ... The Initialize procedure can be used to solve that problem. ... If you're using the shell's memory manager, ...
    (alt.comp.lang.borland-delphi)
  • EnumConverter interfering with Designer-Generated Code
    ... string representations of an enum's values. ... every enum whose values I desire to be displayed as localized ... "ShortDistance" but the Designer-Generated code looks like this: ... Design-Time or at Run-Time (so that I can use the localization ...
    (microsoft.public.dotnet.languages.csharp)