RestrictTo
annotation is used to restrict the scope of the variable to which it is annotated. Few scopes that are listed in the RestrictTo annotation are LIBRARY
, LIBRARY_GROUP
, TESTS
, SUBCLASSES
. When the variable is annotated with the restrictTo annotation, variable's attribute won't be listed as a suggestion in android studio.
For example, if I annotate the variable in the getter
@RestrictTo(RestrictTo.Scope.LIBRARY)
public @Nullable StudentInfo getInfo() {
return mStudentInfo;
}
class StudentInfo {
private String mAddress
@RestrictTo(RestrictTo.Scope.LIBRARY)
StudentInfo(String address) {
mAddress = address
}
public String getAddress() {
return mAddress
}
}
In the above example since StudentInfo is restricted with the scope of LIBRARY, getAddress of the StudentInfo method won't be listed as a suggestion in IDE when called from outside the scope of the library.