我正在研究代码A。我希望直接将空lambda表达式助理到
onValueChange
用于测试。
但是代码B、代码C和代码D都错了,我怎么能分配一个null
lambda (String) -> Unit
到变量
onValueChange
?
代码A
@Composable
fun HelloContent(name2: String, onNameChange: (String) -> Unit) {
Column(modifier = Modifier.padding(16.dp)) {
...
OutlinedTextField(
...
onValueChange = onNameChange
)
}
}
代码B
@Composable
fun HelloContent(name2: String, onNameChange: (String) -> Unit) {
Column(modifier = Modifier.padding(16.dp)) {
...
OutlinedTextField(
...
onValueChange = { }
)
}
}
代码C
@Composable
fun HelloContent(name2: String, onNameChange: (String) -> Unit) {
Column(modifier = Modifier.padding(16.dp)) {
...
OutlinedTextField(
...
onValueChange = null
)
}
}
代码D
@Composable
fun HelloContent(name2: String, onNameChange: (String) -> Unit) {
Column(modifier = Modifier.padding(16.dp)) {
...
OutlinedTextField(
...
onValueChange = fun(x:String):Unit{ }
)
}
}