[英]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.