> For the complete documentation index, see [llms.txt](https://yoyo840821.gitbook.io/android-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yoyo840821.gitbook.io/android-learning/android-annotation.md).

# Android Annotation

dependency:

```
dependencies {
    // If you stay on Support Library
    implementation 'com.android.support:support-annotations:28.0.0'    // If you use AndroidX
    implementation 'androidx.annotation:annotation:1.0.1'
}
```

限定參數型別，類似防呆的做法，像是

```java
private void showToast(Context context, @StringRes strMsg)
{
    Toast.makeText(context, strMsg, Toast.LENGTH_SHORT).show();
}
```

或是Java與kotlin協作的時候可以用到non-null的判斷

```java
private void showMsg(@NonNull SimpleObj obj)
{
        ...
}
```

數字範圍判斷：IntRange/FloatRange

```java
public void count(@IntRange(from = 1, to = 100) int times)
{

}
```

IdRes/LayoutRes/DrawableRes/...\[Any]Res

要求某權限：ex.\@RequirePermission(Manifest.permission.ACCESS\_FINE\_LOCATION)
