当我想使用工件构建jar文件时,我收到以下错误:
警告:java:注意: /Users/doekewartena/IdeaProjects/LemmingsWalker/Java-Base/src/com/github/lemmingswalker/ListDivisor.java 使用未经检查或不安全的操作。警告:java:注意:重新编译 with -Xlint:取消选中以获取详细信息。
我仍然得到一个jar文件,但我在另一个项目中遇到问题,我认为这与此有关。
我在stackoverflow上看到了解决方案。大多数时候,人们似乎使用new ArrayList()
代替new ArrayList<TheType>()
。就我而言,它可能是类似的东西,但我无法找到它。我希望有人可以。
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);
}
// =====================================================================
}
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);
}
}
答案 0 :(得分:2)
字段instanceHelper
是InstanceHelper
的{{3}}。您应该使用类型参数T
:
InstanceHelper<T> instanceHelper;
完成后,您可以将投射移至T
:
for (int i = list.size(); i < toIndex; i++) {
list.add(instanceHelper.createInstance());
}