请在题号前提供的横线上写下正确答案所对应的字母(A–E)。例如,如果你在第 1 题选择 A 和 E,则在 Q1 旁边的横线上写 “A, E”。
Q1
English Question
When using var <propertyName>: <Type> by remember { mutableStateOf("") } to create an instance of MutableState, which of the following statements are true about the by keyword?
Select one or two options.
A. The by keyword delegates the responsibility of getting and setting the property’s value to a MutableState object.
B. When using the by keyword with
MutableState
, we must access the value using
.value
.
C. When using the by keyword, the property’s type will be MutableState.
D. When using the by keyword, the property is always treated as a String.
E. The by keyword allows you to read and write the property directly without using .value.
中文题目
当使用 var <propertyName>: <Type> by remember { mutableStateOf("") } 来创建一个 MutableState 实例时,下面关于 by 关键字的说法哪些是正确的?
选择一个或两个选项。
A. by 关键字会把属性的读取和赋值责任委托给一个 MutableState 对象。
B. 使用 by 关键字配合 MutableState 时,必须通过 .value 来访问值。
C. 使用 by 关键字时,这个属性本身的类型会变成 MutableState。
D. 使用 by 关键字时,这个属性一定会被当作 String 类型处理。
E. by 关键字允许你直接读取和修改这个属性,而不需要使用 .value。
正确答案
A, E
中文答案解析
这题考察的是 Jetpack Compose 中 remember + mutableStateOf + by 的写法。
如果你写:
这里的 by 是 Kotlin 的 属性委托。它会把 name 的读取和赋值操作委托给 MutableState 对象。也就是说,底层仍然是一个 MutableState,但是你在 UI 代码中可以直接写:
不需要写:
所以:
A 正确:by 确实把 get / set 委托给 MutableState。
E 正确:使用 by 后可以直接读写属性,不需要 .value。
B 错误:如果不用 by,才需要 .value。例如:var name = remember { mutableStateOf("") }。
C 错误:使用 by 后,属性类型是内部值的类型,例如 String,不是 MutableState<String>。
D 错误:属性是什么类型取决于 mutableStateOf() 中的值,不一定永远是 String。
Q2
English Question
How does a ViewModel support navigation-related scenarios in Jetpack Compose?
Select one or two options.
A. It is the required mechanism through which all navigation transitions must be triggered in Jetpack Compose, replacing the NavController in the declarative UI.
B. It directly manages the navigation back stack entry and determines the order of navigation actions between composable screens.
C. It serves as a state holder shared across composable destinations, allowing data to persist and be reused without passing it through navigation arguments.
D. It is only compatible with traditional View-based Android navigation and should not be used in Jetpack Compose applications.
E. It ensures that UI-related state is retained across recompositions and configuration changes.
中文题目
在 Jetpack Compose 中,ViewModel 如何支持和导航相关的场景?
选择一个或两个选项。
A. 它是 Jetpack Compose 中触发所有页面导航跳转的必需机制,并且会取代声明式 UI 中的 NavController。
B. 它直接管理导航返回栈,并决定 composable 页面之间导航动作的顺序。
C. 它可以作为多个 composable 页面之间共享的状态持有者,让数据可以保留和复用,而不需要全部通过 navigation arguments 传递。
D. 它只兼容传统 View 系统的 Android Navigation,不应该在 Jetpack Compose 应用中使用。
E. 它可以确保 UI 相关状态在 recomposition 和 configuration changes 后仍然保留。
Which of the following statements is true about the role of the companion object and synchronized in the Room Database?
Select one or two options.
A. The companion object is used to implement the singleton pattern, while synchronized ensures multiple threads can read and write at the same time.
B. The companion object creates a new database instance each time, and synchronized helps increase performance by avoiding read and write locks.
C. The companion object allows database queries to be executed in the background, while synchronized handles main thread updates.
D. The companion object ensures that only one instance of the database is created, and synchronized ensures that if multiple threads try to access the database at the same time, only one thread creates the instance.
E. The companion object can only be accessed only after creating an instance of the class, and synchronized ensures that the database instance can only be accessed by one thread at a time.