amadeu01
03/18/2019, 12:58 PMwith
when the variable é optional? for instance,
inside a fragment, the activity
is optional, so can I use something like
private fun goToMain() = with(activity) {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finishAffinity()
}
Vladimir Petrakovich
03/18/2019, 1:00 PMactivity?.run { }
ghedeon
03/18/2019, 1:04 PM.run{}
is the equivalent of with
plus nullable support, so one might think that the usage of with
is a bit questionable.amadeu01
03/18/2019, 1:08 PMwith
is more readableghedeon
03/18/2019, 1:16 PMwith
then realised this limitation, then didn't want to mix both for basically the same thing and refactor every time I switch null/nullable... Ended up using .run
almost everywhere.LeoColman
03/18/2019, 1:34 PMwithOptional
or something