今天在阅读开源项目Canal的源码过程中发现一个写法被IDEA检测并提醒可以修改,后来意识到这开源项目写法十分严谨且没有问题。
避免为null报错方法:
hints != null ? !hints.equals(that.hints) : that.hints != null
(代码来自开源项目Canal)
代码写完IDEA可能提醒可以直接修改为 !hints.equals(that.hints)
但是修改后就无法防止为null的情况了
今天在阅读开源项目Canal的源码过程中发现一个写法被IDEA检测并提醒可以修改,后来意识到这开源项目写法十分严谨且没有问题。
避免为null报错方法:
hints != null ? !hints.equals(that.hints) : that.hints != null
(代码来自开源项目Canal)
代码写完IDEA可能提醒可以直接修改为 !hints.equals(that.hints)
但是修改后就无法防止为null的情况了