[concurrency-interest] ConcurrentReferenceMap enhancement to 166 - Feedback Requested

Jed Wesley-Smith jed at atlassian.com
Wed Apr 16 23:28:25 EDT 2008


Jason T. Greene wrote:
> Jason Mehrens wrote:
>   
>> Why not use the class type of the references.
>> I.E. ReferenceMap.newMap(WeakReference.class, Reference.class) //weak 
>> keys, strong values.
>> Maybe that is too much of an enum anti-pattern.
>>     
>
> Clever/interesting idea. Although, I still think an enum is better 
> because you immediately know all possible values, and you have nice 
> static type checking.
>   


Wouldn't something like the following on ReferenceType give the same 
benefit:

public static ReferenceType forRef(final Class<?> klass) {
    if (WeakReference.class.isAssignableFrom(klass)) {
        return WEAK;
    }
    if (SoftReference.class.isAssignableFrom(klass)) {
         return SOFT;
    }
    // maybe throw IllegalArg if not a Reference class???
    return STRONG;
}

Then you could also have a newMap(Class<?> keyRefClass, Class<?> 
valueRefClass) method
if required.

cheers,
jed.


More information about the Concurrency-interest mailing list