问题 Kotlin has a feature called string templates. Is it safe to use nullable variables inside a string? override fun onMessageReceived(messageEvent: MessageEvent?) { Log.v(TAG, "onMessageReceived: $messageEvent") } Will the above code throw NullPointerException if messageEvent is null ? 回答1: You can always make a tiny project on try.kotlinlang.org and see for yourself: fun main(args: Array<String>) { test(null) } fun test(a: String?) { print("result: $a") } This code compiles fine and prints null