@Retention(CLASS) @Target({TYPE_USE,METHOD}) public @interface UnownedOuter
Annotating an inner class means to remove its ownership on a referenced outer object so that the reference is not included in the reference count. An anonymous inner class can be annotated with an internal method.
This class can solve the problem in which a field of an outer class instance cannot be annotated because
no explicit declaration is provided when this field is implicitly captured by a Java inner class.
If an inner class cannot be defined as a static nested class, an outer class instance must be used and
you can use UnownedOuter to annotate the inner class to eliminate circular reference.
Incorrect use of this class may result in the same consequence as Unowned, leading to an early release of
the referenced object.
Please refer the following sample code:
class Outer{
@UnownedOuter
private class Inner {
...;
}
Private Runnable r = new Runnable() {
@Override
@UnownedOuter
Public void run() {
...;
}
}
}