我编译了一个Maven Java项目,并按预期进行了编译和运行,但是当我提交到GitHub时,Travis CI说我有“可能从长整数转换为整数的错误”错误。我检查了一下,我相信我所拥有的都是整数,这是相关代码:
public static final String FIELD_COUNT_PROPERTY = "fieldcount";
public static final String FIELD_COUNT_PROPERTY_DEFAULT = "10";
int fieldcount;
private List<String> fieldnames;
public static final String FIELD_NAME_TITLES = "fieldnametitles";
public static final String FIELD_NAME_TITLES_DEFAULT = "0";
private String fieldnametitles;
fieldcount =
Integer.parseInt(p.getProperty(FIELD_COUNT_PROPERTY, FIELD_COUNT_PROPERTY_DEFAULT));
fieldnametitles = p.getProperty(FIELD_NAME_TITLES, FIELD_NAME_TITLES_DEFAULT);
if (fieldnametitles == "0") {
fieldnames = new ArrayList<>();
for (int i = 0; i < fieldcount; i++) {
fieldnames.add("field" + i);
}
} else {
fieldnames = new ArrayList<>(Arrays.asList(fieldnametitles.split(",")));
int fieldcountadj = fieldcount - fieldnames.size();
for (int i = 0; i < fieldcountadj; i++) {
fieldnames.add("field" + i);
}
}
如您所见,fieldcountadj,fieldcount被声明为int,也许无法将fieldnames.size()识别为int?我试图将其更改为(int),但是它被声明为多余。
在Travis CL上显示的错误是:
[错误] /home/travis/build/brianfrankcooper/YCSB/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java:[408,38] 不兼容的类型:可能从long到int的有损转换
这在'int fieldcountadj = fieldcount-fieldnames.size();'行中引用了'-'符号。