I'm going to write my own Python-Java interface. It is compiled as a DLL and wrapped using ctypes.
Yet, it is possible to find Java-classes and allocate Java-objects. But what would be an interface to another language without using those objects methods? My aim is to make this as natural as possible. Unfortunately, it isn't just possible to find Java-methods only by name.
My model is the following:
JClass
JObject
JMethod
Represents a method of a Java-object. It contains the name and signature of the desired method. The signature is evaluated dynamically by the classes that are given on initialization.
Example:
mainMethod = JMethod('main', JStringArray)
Note that JStringArray
is an instance of JClass that represents a string-array.
A JMethod can be added to a JClass instance. But can then be called only from an instantiated JObject.
JStaticMethod
Built-In types
I'm doing JInt
, JShort
, JLont
, JChar
, etc.. to be the
built-in wrapper types.
Like:
JInt = JClass('java/lang/Integer')
JShort = JClass('java/lang/Short')
JString = JClass('java/lang/String')
Question(s):
va_list
or something? I just need to find some way to call a method from Python in Java!typedef jobject jclass; In C++, JNI introduces a set of dummy classes to enforce the subtyping relationship. For example: class _jobject {}; class _jclass : public _jobject {}; ...
JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).
Introduction to Java Native Interface: Establishing a bridge between Java and C/C++ JNI (Java Native Interface) is a foreign function interface that allows code running on JVM to call (or be called by) native applications. Using JNI, one can call methods written in C/C++ or even access assembly language.
1. What do I think of this design?
it's not clear what actual problem you're trying to solve.
what about edge cases; error-handling; forward-/backward-compatibility; bugs in Python/Java? Not fun, but essential for robust software.
mixing two languages is hard enough, mixing three is sure to be much much worse. I would expect major maintainability and coupling problems.
there are already solutions to these problems. RPC, for getting programs in different languages to talk to each other. Jython, for Java/Python interoperability. I believe, Jython even allows you to create Python objects in Java and vice versa directly. Clarifying any shortcomings of these existing systems, and how you would address these shortcomings, would be helpful.
Here are a few missing things:
2. I just need to find some way to call a method from Python in Java! What about Jython, RPC, or just calling an executable?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With