简体   繁体   中英

How can I make a case insensitive keyset ConcurrentHashMap in java?

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?

class CaseInsensitiveConcurrentHashMap <T>

Your hashmap takes a single generic parameter.

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

CaseInsensitiveConcurrentHashMap仅具有一个用于值的通用参数,因此应使用new CaseInsensitiveConcurrentHashMap<SomeClass>()进行实例化

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM