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
- An instance of this class represents a Java class.
JObject
- An instance of this class represents a Java-object. It has to be
initialized with a JClass-instance. (yet, of course, later there
should be arguments for the constructor also.)
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
JStringArrayis 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
- Just like the JMethod, but it can also be called from a JClass
instance.
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):
- What do you think about this design?
- The JNI-Functions for calling methods of a Java-class / -object all
take a variable amount of arguments. After reading several topics on
calling a function with variable arguments from a function that does so,
and also asked a question here on SO, I’m aware that this is not possible.
Now, are there functions that don’t take a variable number of arguments
but ava_listor something? I just need to find some way to call a method from Python in Java!
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?