How to implement a java interface in c++?

Andrew Haley aph@redhat.com
Thu May 18 14:25:00 GMT 2006


tsuraan writes:
 > > 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?
No.
 > 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?
I doubt it. In any case, In any case there's a simple way that works:
write the headers in as .java files and the inplementation in C++.
Andrew.


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /