警告:[unchecked]未检查的调用put(K,V)作为原始类型的成员java.util.Hashtable localParams.put(name,values);

前端之家收集整理的这篇文章主要介绍了警告:[unchecked]未检查的调用put(K,V)作为原始类型的成员java.util.Hashtable localParams.put(name,values);前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有两个警告:
– 第一是:
HELPDESKGESTION2\src\java\glpi\filter\LoginFilter.java:289: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Hashtable
                    localParams.put(key,value);
                                   ^

– 二是:

HELPDESKGESTION2\src\java\glpi\filter\LoginFilter.java:292: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Hashtable
            localParams.put(name,values);
                           ^

代码生成这个警告是:

public void setParameter(String name,String []values) {
    if (debug) System.out.println("LoginFilter::setParameter(" + name + "=" + values + ")" + " localParams = "+ localParams);

    if (localParams == null) {
    localParams = new Hashtable();
    // Copy the parameters from the underlying request.
    Map wrappedParams = getRequest().getParameterMap();
    Set keySet = wrappedParams.keySet();
    for (Iterator it = keySet.iterator(); it.hasNext(); ) {
        Object key = it.next();
        Object value = wrappedParams.get(key);
        localParams.put(key,value);
    }
    }
    localParams.put(name,values);
}

解决方法

更换:
localParams = new Hashtable();

附:

localParams = new Hashtable<String,String>();

我假设你有一个全局变量,如下所示:

private Hashtable localParams;

替换为:

private Hashtable<String,String> localParams;

如果您进行更改,我建议警告将消失,但您也必须用String替换所有的Object;

原文链接:https://www.f2er.com/java/125868.html

猜你在找的Java相关文章