Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Android Support Annotations "RestrictTo"

Tags:

android

I was understanding the android support annotations in which i came across "@RestrictTo" annotation; Which explains the different scopes developer can define. Can anyone explain in detail with some example how to use these annotations?

Any leads will be appreciated!

like image 263
Pavan Avatar asked Apr 27 '17 11:04

Pavan


People also ask

What is Android support annotation?

Annotations allow you to provide hints to code inspections tools like Lint, to help detect these more subtle code problems. They are added as metadata tags that you attach to variables, parameters, and return values to inspect method return values, passed parameters, local variables, and fields.

What is IntDef?

Kotlin |Java. @Retention(value = AnnotationRetention.SOURCE) @Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS]) annotation IntDef. Denotes that the annotated element of integer type, represents a logical type and that its value should be one of the explicitly named constants.


1 Answers

It is used for meta programming access modifiers. Java will allow to access any public method from anywhere, while @RestrictTo applies to RestrictTo.Scope extends the accessing restrictions to other scopes not known to Java itself.

GROUP_ID
LIBRARY
LIBRARY_GROUP
SUBCLASSES
TESTS

Where for example SUBCLASSES would act like protected while being accessible from anywhere if the developer wants to.

Basically you could view it as suggestions, not any direct compiler enforcement.

like image 166
tynn Avatar answered Sep 28 '22 18:09

tynn