简体   繁体   English

编译警告:使用未经检查或不安全的操作

[英]compile warning: uses unchecked or unsafe operations

When I want to build a jar file using artifacts I get the following error: 当我想使用工件构建jar文件时,出现以下错误:

Warning:java: Note: /Users/doekewartena/IdeaProjects/LemmingsWalker/Java-Base/src/com/github/lemmingswalker/ListDivisor.java uses unchecked or unsafe operations. 警告:java:注意:/Users/doekewartena/IdeaProjects/LemmingsWalker/Java-Base/src/com/github/lemmingswalker/ListDivisor.java使用未经检查或不安全的操作。 Warning:java: Note: Recompile with -Xlint:unchecked for details. 警告:java:注意:使用-Xlint:进行重新编译:未经检查以获取详细信息。

I still get a jar file but I have problems in another project which I think are related to this. 我仍然得到一个jar文件,但是在另一个我认为与此有关的项目中遇到了问题。 I have seen solutions on stackoverflow. 我已经看到了关于stackoverflow的解决方案。 Most of the times people seem to use new ArrayList() instead of new ArrayList<TheType>() . 大多数时候,人们似乎使用new ArrayList()而不是new ArrayList<TheType>() In my case, it might be something similar, but I can't finds it. 就我而言,可能是类似的东西,但我找不到。 I hope someone can. 我希望有人可以。

public class ListDivisor<T> {

    List<T> list;

    int subListStartIndex = 0;
    int currentGetIndex = 0;

    InstanceHelper instanceHelper;


    public ListDivisor(List<T> list, InstanceHelper<T> instanceHelper) {
        this.list = list;
        this.instanceHelper = instanceHelper;
    }

    // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


    public void reset() {
        subListStartIndex = 0;
        currentGetIndex = 0;

        if (instanceHelper.doResetInstances()) {
            for (T obj : list) {
                instanceHelper.resetInstance(obj);
            }
        }
    }

    // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


    public SubListGetter<T> getSubListGetter(int size) {

        int fromIndex = subListStartIndex; // inclusive
        int toIndex = fromIndex + size; // exclusive

        for (int i = list.size(); i < toIndex; i++) {
            list.add((T) instanceHelper.createInstance());
        }

        subListStartIndex = toIndex;
        currentGetIndex = toIndex;

        //return list.subList(fromIndex, toIndex);
        return new SubListGetter(fromIndex, toIndex, list);
    }

    // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    /**
     * Returns a subList starting where the previous subList ended till
     * the latest object added till then.
     *
     * @return
     */
    public SubListGetter<T> getSubListGetter() {
        return getSubListGetter(currentGetIndex - subListStartIndex);
    }

    // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


    public T getNext() {

        if (currentGetIndex >= list.size()) {
           list.add((T)instanceHelper.createInstance());
        }

        return list.get(currentGetIndex++);

    }

    // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


    public void clear() {
        list.clear();
        reset();
    }


    // =====================================================================

    public interface InstanceHelper<T> {
        public T createInstance();
        public boolean doResetInstances();
        public void resetInstance(T obj);
    }

    // =====================================================================


}

And the SubListGetter class: 和SubListGetter类:

public class SubListGetter<T> {

    int fromIndex, toIndex;
    List<T> target;

    public SubListGetter (int fromIndex, int toIndex, List<T> target) {
        this.fromIndex = fromIndex;
        this.toIndex = toIndex;
        this.target = target;
    }

    public List<T> getSubList() {
        return target.subList(fromIndex, toIndex);
    }

}

The field instanceHelper is a raw type of InstanceHelper . 字段instanceHelperInstanceHelper原始类型 You should use the type parameter T : 您应该使用类型参数T

InstanceHelper<T> instanceHelper;

You can remove the casting to T once that's complete: 完成后,您可以将演员表移至T

for (int i = list.size(); i < toIndex; i++) {
   list.add(instanceHelper.createInstance());
}

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

相关问题 编译器警告类使用未经检查或不安全的操作 - Compiler Warning class uses unchecked or unsafe operations 使用未经检查或不安全的操作 - Uses unchecked or unsafe operations 不安全或未经检查的操作警告 - Unsafe or unchecked operations warning JavaFX编译警告 - “使用未经检查或不安全的操作” - 原始数据类型? - JavaFX Compilation Warning - “uses unchecked or unsafe operations” - Raw Data Types? 是什么导致 javac 发出“使用未经检查或不安全的操作”警告 - What causes javac to issue the "uses unchecked or unsafe operations" warning 可比较使用未经检查或不安全的操作 - Comparable uses unchecked or unsafe operations Android:使用未经检查或不安全的操作 - Android: uses unchecked or unsafe operations “使用未经检查或不安全的操作”警告 - “uses unchecked or unsafe operation” warning 注意:Anpr.java 使用未经检查或不安全的操作。 注意:使用 -Xlint 重新编译:未选中 JComboBox 中的详细警告 - Note: Anpr.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details warning in JComboBox 使用未经检查或不安全的操作,使用 -Xlint 重新编译 - Uses unchecked or unsafe operations, recompile with -Xlint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM