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!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With