attempted to return null from a method with a primitive return type (int)
时间: 2023-04-28 22:03:17 浏览: 85
在Java中,如果一个方法的返回类型是基本数据类型(如int、double等),则不能返回null。如果你试图从这样一个方法中返回null值,就会出现编译错误,例如“attempted to return null from a method with a primitive return type (int)”。这是因为Java中的基本数据类型是值类型,不能为null,而只有引用类型才能为null。如果你想要在方法中返回一个可能为null的值,可以将方法的返回类型改为对应的包装类类型(如Integer、Double等),这些类可以表示null值。
相关问题
del' attempted to return null from a method with a primitive return type (int)
这个错误提示是因为在Java中,原始数据类型(如int、double等)不能为null,但是在Mapper方法'com.kkb.mapper.TeamMapper.delete'中,返回了null值。为了解决这个问题,可以将返回类型改为Integer或者使用默认值来代替null值。
另外,引用中提供了两个Mapper映射文件的查询语句,一个是根据id查询团队信息,另一个是添加团队信息。这两个查询语句与问题本身没有直接关系,但是可以作为参考,帮助你更好地理解Mapper映射文件的编写。
attempted to return null from a method with a primitive return type (int).分析错误
这个错误通常发生在你定义了一个返回类型为 int 的方法,但是在方法中没有返回任何值,或者返回了 null 值。由于 int 是一个原始数据类型,它不能为 null,因此会出现编译错误。
要解决这个问题,你需要确保在方法中返回一个 int 类型的值,或者将返回类型改为 Integer 类型,这样就可以返回 null 值了。你可以检查一下你的方法中是否有缺少返回语句或者返回类型与方法定义不匹配的情况。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)