[英]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
. 字段
instanceHelper
是InstanceHelper
的原始类型 。 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.