繁体   English   中英

如何在Java中创建不区分大小写的键集ConcurrentHashMap?

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

我试图用我的CaseInsensitiveConcurrentHashMap替换对ConcurrentHashMap使用。 但是,我无法实例化我的哈希图。 我将提供我的实现。

哈希映射类-来自SO问题: 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());
    }
}

我下面的代码不适用于新的哈希映射:

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>>>();
}

tester两行都失败。 这是我的错误信息:

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

关于我可以尝试的任何想法?

class CaseInsensitiveConcurrentHashMap <T>

您的哈希图采用单个通用参数。

因此,在使用它时,必须仅传递一个通用参数。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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