Can a Java class implement a C ++ interface

Is it possible to implement a Java class to implement the C ++ interface (an interface means a full abstract class)? Where can I find out more?

+3
source share
6 answers

Not directly, no. However, you can create an implementation of this interface in C ++ that simply delegates the Java implementation through JNI. See the JNI Specification for more details .

+2
source

Yes, you should use JNI .

Here is a tutorial from Sun / Oracle

+2
source

, . ++ .

+1

JNI JNA. , ( C/++).

0

++- BridJ ( JNA, ++), .

: 0.4, BridJ ++- Java

++:

#ifndef TEST_EXPORTS
#define TEST_EXPORTS
#endif
class TEST_EXPORTS TestClass {
public:
    virtual int add(int a, int b);
};

Java BridJ:

public class TestClass extends CPPObject { 
    @Virtual(0) 
    public native int add(int a, int b); 
}; 

++ Java:

TestClass test = new TestClass() { 
    @Override 
    public int add(int a, int b) { 
        return a + b; 
    } 
}; 
0

Java- Java. Java/++ JNI.

-1

Source: https://habr.com/ru/post/1741117/


All Articles