Question

I am trying to replace my use of ConcurrentHashMap with mine CaseInsensitiveConcurrentHashMap. However, I cannot instantiate my hashmap. I will provide my implementations.

The hash map class - based from SO question: https://stackoverflow.com/a/8237007/850475

import java.util.concurrent.ConcurrentHashMap;

public class CaseInsensitiveConcurrentHashMap <T> extends ConcurrentHashMap<String, T>{

    @Override
    public T put(String key, T value) {
        return super.put(key.toLowerCase(), value);
    }

    public T get(String key) {
        return super.get(key.toLowerCase());
    }
}

And my code below that does not work with the new hash map:

public class tester {
    private static ConcurrentMap<String, SomeClass> items = new CaseInsensitiveConcurrentHashMap<String, SomeClass>();  
    private static ConcurrentMap<String, CaseInsensitiveConcurrentHashMap<String, Collection<SomeClass2>>> tagMap = new CaseInsensitiveConcurrentHashMap<String, CaseInsensitiveConcurrentHashMap<String, Collection<SomeClass2>>>();
}

Both lines in tester fail. This is my error message:

Incorrect number of arguments for type CaseInsensitiveConcurrentHashMap<T>; it cannot be parameterized with arguments <String, Collection<SomeClass>>

Any idea as of what I can try?

Was it helpful?

Solution

The CaseInsensitiveConcurrentHashMap has only one generalized parameter for the values, so it should be instanced using new CaseInsensitiveConcurrentHashMap<SomeClass>()

OTHER TIPS

class CaseInsensitiveConcurrentHashMap <T>

Your hashmap takes a single generic parameter.

Therefore, when you use it, you must pass only one generic parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top