Re: Using CNI on inner classes
Andrew Haley <[email protected]>
| Newsgroups | gmane.comp.gcc.java.devel |
|---|---|
| Message-ID | <[email protected]> |
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 > So, ideally gcjh would add friend declarations, like the above, > automatically to inner classes to approximate the Java semantics. That's a nice idea. There's no reason why not; I just think no-one ever thought of it. > But, the easiest fix here is just to make the private method > package-private instead. I think so. Andrew.