Re: Using CNI on inner classes
Andrew Haley <[email protected]>
| Newsgroups | gmane.comp.gcc.java.devel |
|---|---|
| Message-ID | <[email protected]> |
Andrew Haley wrote: > Bryce McKinlay wrote: >> On Thu, Aug 13, 2009 at 10:10 AM, Andrew Haley<[email protected]> wrote: >> >>> If the method is declared private, it really will be private, even >>> to cni. >>> >>> If you really need to breach privacy, you can do this in Test$Inner.h: >>> >>> class Test$Inner : public ::java::lang::Object >>> { >>> friend class ::Test; >>> >>> but I can't really see the point of private methods in an inner class >>> that you actually intend to be called from the enclosing class. >> In Java the private methods are accessible to the enclosing class. > > Ah yes, that rule, the one that requires all the "synthetic access$0" > business. I just did a web search to find out the reason for this > rather odd rule, and I found "... inner classes can access all members > of the declaring class, even private members. In fact, the inner class > itself is said to be a member of the class; therefore, following the > rules of object-oriented engineering, it should have access to all > members of the class." > http://onjava.com/pub/a/onjava/excerpt/HardcoreJava_chap06/index.html Actually, that doesn't explain it: it only explains why inner classes can access the private methods of enclosing classes, not vice versa. Andrew.