Using CNI on inner classes
Andrew Haley
aph@redhat.com
Thu Aug 13 09:10:00 GMT 2009
Vaijayanthi Mala Suresh wrote:
> Hi,
>> I have an Test.java as shown below
>>> public class Test {
>> private native void natRegister(Inner obj);
> Inner myInnerClassObj;
>> class Inner
> {
> private void printline()
> {
> System.out.printline("Prints from printline");
> }
> Inner()
> {
> }
> }
>> public Test()
> {
> myInnerClassObj = new Inner();
> }
>> public void register()
> {
> natRegister(myInnerClassObj);
> }
>>> public static void main(String [] args) {
> System.out.println("Hello from main");
> Test ht = new Test();
> ht.register();
> }
> }
>> I have the Test.cc defined as shown below
> // This file is intended to give you a head start on implementing native
> // methods using CNI.
> // Be aware: running 'gcjh -stubs' once more for this class may
> // overwrite any edits you have made to this file.
>> #include <gcj/cni.h>
> #include <java/lang/UnsupportedOperationException.h>
>> #include "Test.h"
> #include "Test$Inner.h"
> void
> Test::natRegister(::Test$Inner *innerObj)
> {
> innerObj->printline();
> }
>> I need to access the private method from the native code. This was
> possible in JNI but it is not possible in CNI.
>> Can you please suggest me a solution for this using CNI.
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.
Andrew.
More information about the Java
mailing list