Null return value from advice does not match primitive return type for

1、org.springframework.aop.AopInvocationException:Null return value from advice does not match primitive return type for
这个错就是返回的类型不匹配

 

 

 

 

2、原因:

主要还是基本数据类型无法接受null,如果环绕返回null就报错,可以将boolean改成Boolean。

 

 

 


3、Boolean.TRUE 和 true 区别?

Boolean A(){
    return Boolean.TRUE;
}
boolean B(){
    return Boolean.TRUE
}
Boolean C(){
    return true;
}
boolean D(){
    return true;
}

 

在性能和​​内存使用效率方面,A、B效率最高,C、D会更慢,因为需要装箱和拆箱。
所以建议 Boolean 返回类型函数建议 return Boolean.TRUE;这种写法!

posted @ 2022-11-07 16:06  llili  阅读(1679)  评论(0)    收藏  举报