[android-developers] Dev Guide misunderstands static classes?
Hi there
In the Dev Guide section on Building Custom Components (http://
developer.android.com/guide/topics/ui/custom-components.html), we
read:
* It is static, meaning it does not generate the so-called "synthetic
methods" that allow it to access data from the parent class, which in
turn means that it really behaves as a separate class rather than
something strongly related to NoteEditor. This is a cleaner way to
create inner classes if they do not need access to state from the
outer class, keeps the generated class small, and allows it to be used
easily from other classes.
This mischaracterizes the difference between static and non-static
(inner) nested classes. The generation of synthetic methods is not
related to whether the class is static or not, but to the visibility
of the object being accessed in the "other" class (it works both from
inner to outer and vice versa). If the outer (inner) class defines a
private method or field, then when it's accessed from within the inner
(outer) class, a hidden accessor method will be generated on the outer
(inner) class to cross the "private" boundary. Of course, if the inner
class is static, the outer field or method being accessed would also
have to be static.
Making the nested class static does not in itself avoid the generation
of any synthetic methods: if any of them are private, those accessors
will be generated regardless. What a non-static nested class DOES
generate is a hidden reference to the outer instance, in order for its
fields and methods to be accessed, but that access doesn't require the
generation of synthetic methods unless their visibility demands it.
It's a small but important error in the documentation, and it would be
nice to see it fixed.
Cheers,
Pete
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home