【发布时间】:2021-06-15 17:55:03
【问题描述】:
我是 Kotlin 的新手,从几天开始我就在 android studio 上玩了一下。这是我正在处理的课程:
class MyDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return activity?.let {
val builder = AlertDialog.Builder(it)
builder.setMessage(R.string.exit)
builder.setPositiveButton(R.string.positive) { _: DialogInterface, _: Int -> }
builder.create()
} ?: throw Exception("problem detected with throw Exception on creating Dialog")
}
}
我不明白返回的是什么
return activity?.let {
val builder = AlertDialog.Builder(it)
builder.setMessage(R.string.exit)
builder.setPositiveButton(R.string.positive) { _: DialogInterface, _: Int -> }
builder.create()
} ?: throw Exception("problem detected with throw Exception on creating Dialog")
我知道有趣的是 onCreateDialog 返回一个“Dialog”对象,因为
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog
正在返回一个对话框类型(代码实际上是有效的),但我不明白在这种情况下“返回”是如何工作的,我是否返回了所有括号内容?谢谢大家!
【问题讨论】:
标签: android kotlin dialog nullable return-type