在使用@DeleteMapping注解的Java代码中,您可能遇到以下代码:

@DeleteMapping("/{id}")
public void delete(@PathVariable int id){
   this.arrayList= this.arrayList.stream()
      .filter(s->s.getId()==id)
      .collect(Collectors.toList());
}

您可能会疑惑为什么 s->s.getId()id 不是使用 .intValue() 方法转换为 Integer 类型进行比较。

在这种情况下,s.getId()idint 类型,不需要使用 intValue() 方法将其转换为 Integer 类型。因此,您可以直接使用 s.getId()id 进行比较。

这是因为 Java 在进行比较操作时,会自动将 int 类型的值转换为 Integer 类型。因此,s.getId()id 的比较操作会自动将 int 类型的值转换为 Integer 类型进行比较,无需手动进行转换。


原文地址: https://www.cveoy.top/t/topic/pkxW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录