val context : Context? = null if (context != null) { val res = context.getResources() // Don't need '?' anymore val appName = res.getString(R.string.app_name) val shortName = appName.substring(0, 2) }
Keddit — Part 2: Kotlin Syntax, Null Safety and more in Android
Juan Ignacio Saravia
79314

You also can use something like:

val context : Context? = null
context?.let {
val res = context.getResources() // Don't need '?' anymore
val appName = res.getString(R.string.app_name)
val shortName = appName.substring(0, 2)
}
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.