I've noticed that when using Kotlin's synthetic binding, the view returned is non null (Kotlin will return View!
). But this doesn't make much sense to me, since findCachedViewById
can actually return null results, meaning that views can actually be null.
public View _$_findCachedViewById(int var1) {
if(this._$_findViewCache == null) {
this._$_findViewCache = new HashMap();
}
View var2 = (View)this._$_findViewCache.get(Integer.valueOf(var1));
if(var2 == null) {
View var10000 = this.getView();
if(var10000 == null) {
return null;
}
var2 = var10000.findViewById(var1);
this._$_findViewCache.put(Integer.valueOf(var1), var2);
}
return var2;
}
So why are they not optional in this case? Why doesn't Kotlin simply return View?
when using synthetic binding, so that developers would be forced to check nullability when dealing with views?
Maybe it's just because I'm new to Kotlin, but I think this is a bit counter intuitive, since the variable is not optional but we are still supposed to check if the View is in fact not null.
So in this case, does it make sense to do something like the code below?
view?.let {
// handle non null view here
}