New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[新特性] 完成Assert 断言工具类,函数接口延迟获取错误信息接口 #1166
Conversation
…oNullElements,notEmpty,notEmpty,state等方法的函数式获取错误信息方法
*/ | ||
public static void isTrue(boolean expression, Supplier<String> errorMsgSupplier) throws IllegalArgumentException { | ||
if (!expression) { | ||
isTrue(false, errorMsgSupplier.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里重复判断了哦,而且推荐false == expression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,idea 推荐直接! ,哈哈哈哈 , 遵循项目规范
但是,这个地方需要在外面嵌套一层判断,不然延迟调用效果将无效 ,
感谢pr,非常辛苦的工作,哈哈。 不过前面的isTrue重复判断了,这块我会做下修改。 |
额……和以前的方法冲突了。
以前有自定义异常。 |
自定义异常是什么场景下使用呢? |
针对不同的异常 添加全局异常处理 会不会好点 |
自定义异常场景非常多。比如在框架中,业务层需要统一处理某种类型异常,这个时候如果写死异常类型,那捕获异常会变得很麻烦。 |
对哦 感觉业务场景 适用于直接生产消息,而不那么关注异常类型 , 框架中更关注 异常类型 当时我加代码时也有考虑到这一点,我后面的那些数值比较就没有添加延迟获取拓展 |
所以为了更好适应,我会把你的pr修改为更加通用性: public static <X extends Throwable> void isNull(Object object, Supplier<X> errorSupplier) throws X {
if (null != object) {
throw errorSupplier.get();
}
} |
那这样针对业务场景就不是那么友好了 , 如果需要使用延迟获取异常消息的话,需要在获取错误消息外再包装一层异常类 两者共存会不会更适用于一个工具类,这也正好迎合 重载 的特性 需要生产错误消息使用这个 ,生产异常类使用另外一个 |
说明
修改描述(包括说明bug修复还是新特性添加)