@get: 在 Android Studio 的 Room 中是什么意思?
What does @get: mean in Room in Android Studio?
以下代码A来自项目https://github.com/enpassio/Databinding
@get:
是什么意思?
代码A
@Dao
interface ToyDao {
@get:Query("SELECT * FROM toys")
val allToys: LiveData<List<ToyEntry>>
@Query("SELECT * FROM toys WHERE toyId = :id")
fun getChosenToy(id: Int): LiveData<ToyEntry>
...
}
get
是可以使用的use-site目标之一。
来自文档:
When you're annotating a property or a primary constructor parameter,
there are multiple Java elements which are generated from the
corresponding Kotlin element, and therefore multiple possible
locations for the annotation in the generated Java bytecode.
要指定应如何准确生成注释,我们可以使用 @get:Query
。
没有必要指定使用地点目标。如果你不指定,它会选择 @Target
,在 @Query
注释中提到,即 @Target(ElementType.METHOD)
参考:https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets
以下代码A来自项目https://github.com/enpassio/Databinding
@get:
是什么意思?
代码A
@Dao
interface ToyDao {
@get:Query("SELECT * FROM toys")
val allToys: LiveData<List<ToyEntry>>
@Query("SELECT * FROM toys WHERE toyId = :id")
fun getChosenToy(id: Int): LiveData<ToyEntry>
...
}
get
是可以使用的use-site目标之一。
来自文档:
When you're annotating a property or a primary constructor parameter, there are multiple Java elements which are generated from the corresponding Kotlin element, and therefore multiple possible locations for the annotation in the generated Java bytecode.
要指定应如何准确生成注释,我们可以使用 @get:Query
。
没有必要指定使用地点目标。如果你不指定,它会选择 @Target
,在 @Query
注释中提到,即 @Target(ElementType.METHOD)
参考:https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets