Question #368MediumNative Android

Important Annotations for Java vs Kotlin vs Dart vs Jetpack Compose

#annotations#kotlin#java#dart

Answer

Overview

Annotations provide metadata to compilers and frameworks.


Comparison Table

Use CaseJavaKotlinDartCompose
Override
text
@Override
text
override
text
@override
text
override
Nullable
text
@Nullable
text
String?
text
String?
text
String?
UI FunctionN/AN/AN/A
text
@Composable
Deprecated
text
@Deprecated
text
@Deprecated
text
@Deprecated
Same
ImmutableManual
text
data class
text
@immutable
text
@Immutable

Java Annotations

java
@Override
public void onClick(View v) { }

@Nullable
String getName() { return name; }

@NonNull
String getEmail() { return email; }

@UiThread
public void updateUI() { }

@WorkerThread
public void fetchData() { }

Kotlin Annotations

kotlin
override fun onClick(v: View) { }

@Deprecated("Use newMethod()")
fun oldMethod() { }

@JvmStatic
fun staticMethod() { }

Dart Annotations

dart

void initState() {
  super.initState();
}


class MyWidget extends StatelessWidget { }


void testHelper() { }

Jetpack Compose Annotations

kotlin
@Composable
fun Greeting(name: String) {
    Text("Hello $name")
}

@Preview
@Composable
fun GreetingPreview() {
    Greeting("Android")
}

@Immutable
data class User(val name: String)

Key Point: Modern languages build features into syntax, reducing annotation needs.