简体   繁体   中英

Can I create Java-classes from C/C++ only?

I have heard about JNI and have tried to use it. What I would want to do is create a Java-class from C or C++ only , ie no Java code like this:

class MyClass {
    static { System.loadLibrary("myclass_impl.dll") }
    native public int someFunction(String string);
}

For example, Python allows to create Extension Classes from C whereby you could also wrap C-functions from a DLL using ctypes.

Is there a way to do this for Java?

Almost certainly not. Java classes must be expressed in Java bytecode, which C and C++ are not (normally) equipped to generate. Additionally, the Java memory model is substantially different from the model in C and C++, and requires its own unusual layout constraints and the like.

Unless you want to be implementing basically an entire Java compiler in C++, I would be surprised if this could be done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM