On Jul 20, 2007, at 17:15, Mark C. Allman wrote:
Hi Mark
Perhaps I'm being a bit dim, but ...
Why store the Property as a key and a value both? Just store "" as
the value. You can still get a list of all the cached Property
objects by calling keySet(). The entries in the Set returned may
be WeakReference objects, but that's easily dealt with.
Just my 2 cents.
Interesting idea, but... the point of storing the Property in key and
value, is being able to do for example:
StringProperty cachedInstance = (StringProperty) Map.get(new
StringProperty(...));
I don't immediately see a convenient solution for that using keySet
()... not at first glance, at least. :/
Note:
As indicated earlier in another thread, the cost of construction of
the related Property subtypes is low enough so as not to cause a
significant overhead. If this were not the case, then an entirely
different strategy would have to be used that avoids the cost of
creation altogether.
If the Property is already cached, the 'new' instance in the call
above doesn't have to leave the stack. Its lifetime is limited to the
execution of get(). We would instead get a reference to a
cachedInstance that was already moved to the heap earlier on.
Clever in concept, but still needs some work, I guess.
Cheers
Andreas