如何避免砂浆演示者getView()的常量空值检查?

我想知道你使用什么方法来避免对Mortar主持人中的getView()进行重复的空检查?

90%的时间是没有必要的,因为一种方法正在响应从视角发起的事情。 在必要的情况下,对某种异步事件做出响应……我们只是应付它。

public void omgTheServerSaid(Some thing) { MyView view = getView(); if (view == null) return; view.showIt(thing.it); } 

这是我从现在开始想要在Kotlin写的东西。

 getView()?.showIt(thing.it); 
Interesting Posts