【问题标题】:What this 'at'/'@' symbol means in Kotlin?这个 'at'/'@' 符号在 Kotlin 中的含义是什么?
【发布时间】:2020-05-21 02:03:40
【问题描述】:

这些注解在 android 中的 Kotlin 代码中是什么意思?

@SuppressLint("SimpleDateFormat")
fun convertLongToDateString(systemTime: Long): String {
    return SimpleDateFormat("EEEE MMM-dd-yyyy' Time: 'HH:mm")
            .format(systemTime).toString()
}

@Entity(tablename = "daily_sleep_quality_table")
data class SleepNight(...)

    ....
    ....

【问题讨论】:

  • 我很困惑,你已经用标签 android-annotationsjava-annotations 标记了你自己的问题,所以你知道这些 注释,你的问题到底是什么那么呢?
  • 我只是想知道它们在代码中的作用或含义。它们看起来像 Python 装饰器。

标签: android kotlin android-annotations java-annotations


【解决方案1】:

那些是 kotlin 支持的Java annotations

Java 注释与 Kotlin 100% 兼容

在你的例子中@Entity

指定类是一个实体。此注解应用于实体类

【讨论】:

    【解决方案2】:

    @ 是 Java annotation,在 Kotlin 中也支持。

    @SuppressLint("SimpleDateFormat")

    @SuppressLint 是 Android Lint 工具使用的注解。每当您的代码中的某些内容不是最佳的或可能崩溃时,Lint 都会告诉您。通过在此处传递“SimpleDateFormat”,您可以取消所有警告,这些警告会告诉您是否以错误的方式使用 SimpleDateFormat。

    @Entity(tablename = "daily_sleep_quality_table")

    @Entity 是 SQLite 用来将类标记为实体的注释。如果你在你的类中使用它,SQLite 会将你的类识别为具有指定表名的实体。

    【讨论】:

      【解决方案3】:

      查看this

      @
      - 介绍了annotation
      - 介绍或引用loop label
      - 介绍或引用lambda label
      - 引用 'this' expression from an outer scope
      - 引用 outer superclass

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-11
        • 2020-10-02
        • 2013-01-06
        • 1970-01-01
        • 1970-01-01
        • 2011-02-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多