在下面的代码中,如果trips是空的,我想显示我的空视图,然后返回并避免运行下面的代码,但是编译器说"这里不允许返回".
mainRepo.fetchUpcomingTrips { trips ->
if (trips.isEmpty()) {
showEmptyViews()
return
}
// run some code if it's not empty
}
Is there a way to return like that?
I know I can just put it in an if else block but I hate writing if else's, it's less understandable/readable in my opinion when there's a few more conditions.