This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to implement a java interface in c++?


No. Just add the "native" keyword to your methods in the java class like
this:

====CppImplementation.java========================
public class CppImplementation implements JavaInterface
{
    public native void doIt():
}
=====================================

Then you add a *.cpp file containing a normal C++ method implementation:

#include "CppImplementation.h"

void
CppImplementation::doIt()
{
  // Do something
}


The needed header file can be generated with gcjh.

This really looks a lot like $ cat CppImplementation.h class CppImplementation : public JavaInterface { public: void doIt(): }

Are there plans in the pipe for allowing this?  It seems like a
pre-processor run could go through and check if c++ classes are
extending java ones, and do some parsing work to re-phrase them to be
java files.  Multiple inheritance wouldn't work that way, but for
simple things it seems like it could be done.  Will it be?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]