Any idea how to optimize such code? (Now nullity c...
# announcements
i
Any idea how to optimize such code? (Now nullity check is done twice..)
Copy code
private var trendingMovies: List<TrendingMovie>? = null

fun doSth(){}
	if(trendingMovies == null)
		getTrendingMovies()
	else
		trendingMovies?.let { showTrendingMovies(it) }
}

private fun showTrendingMovies(list: List<TrendingMovie>){}
Local variable comes to my mind, but I wonder is it the best we can do?
Copy code
fun doSth(){}
	val trendingMovies = trendingMovies

	if(trendingMovies == null)
		getTrendingMovies()
	else
		showTrendingMovies(trendingMovies)
}