What this 'at'/'@' symbol means in Kotlin?

1.4k Views Asked by At

What do these annotations mean in this Kotlin code in android?

@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(...)

    ....
    ....
3

There are 3 best solutions below

0
Ezra Lazuardy On BEST ANSWER

@ is a Java annotation, which also supported in Kotlin.

@SuppressLint("SimpleDateFormat")

@SuppressLint is an annotation used by the Android Lint tool. Lint will tell you whenever something in your code isn't optimal or may crash. By passing "SimpleDateFormat" there, you're suppressing all warnings that would tell you if you're using SimpleDateFormat in a wrong way.

@Entity(tablename = "daily_sleep_quality_table")

@Entity is annotation used by SQLite to marks a class as an Entity. If your using that in your class, SQLite will identify your class as an Entity with the specified table name.

0
Ori Marko On

Those are Java annotations which kotlin supports

Java annotations are 100% compatible with Kotlin

In your example @Entity

Specifies that the class is an entity. This annotation is applied to the entity class

0
Victory On

check this

@
- introduces an annotation
- introduces or references a loop label
- introduces or references a lambda label
- references a 'this' expression from an outer scope
- references an outer superclass