- Redundant boxing inside ‘Integer.valueOf(xx)’
解决办法: 改为Integer.parseInt(xx)即可。因为Integer.valueOf内部调用了parseInt,会提示多余的拆箱操作
- ‘xxx == null ? false : yyy’ can be simplified to 'xxx!=null && yyy
解决办法: 按照提示修改即可。简化写法,原来写法比较啰嗦 - ‘OptionalInt.getAsInt()’ without ‘isPresent()’ check
Pattern pattern = Pattern.compile("^(" + name + "\\()(\\d+)(\\))$");
int max = apps.stream()
.mapToInt(app -> {
Matcher matcher = pattern.matcher(app.getName());
if (matcher.find()) {
String group = matcher.group(2);
return Integer.parseInt(group);
}
return 1;
})
.max()
.getAsInt();
return max + 1;
示例代码中,apps为一个对象列表,经过一些列处理变为某个int值最后取最大值 提示的原因是因为map中有if的判断,所以有可能全部不匹配,此时max()可能返回一个类似Optional为空的一个东西,需要进行类似处理,将getAsInt改为orElse即可
Pattern pattern = Pattern.compile("^(" + name + "\\()(\\d+)(\\))$");
int max = apps.stream()
.mapToInt(app -> {
Matcher matcher = pattern.matcher(app.getName());
if (matcher.find()) {
String group = matcher.group(2);
return Integer.parseInt(group);
}
return 1;
})
.max()
.orElse(1);
return max + 1;
|