Minimum Working Example for pyjnius method overload issues

java
python
imglyb
Tags: #<Tag:0x00007fa30763cae8> #<Tag:0x00007fa30763c818> #<Tag:0x00007fa30763c660>

#1

imglyb is based on PyJNIus, a shared memory Java-Python. As experienced by some users (@bnorthan, @thewtex) , PyJNIus seems to have trouble resolving certain overloaded Java methods. I am trying to compile a minimum working example so that I can open an issue on the PyJNIus github page. So far, I was unsuccessful but this is what I have:

import jnius_config
import os
import subprocess

jnius_config.add_classpath('.')

java_mwe = """
public class MWE
{
    public void doSomething( long[] array ) {
        System.out.println("One argument.");
    }
    
    public void doSomething( long[] array, int[] otherArray ) {
        System.out.println("Two arguments.");
    }
    
}
"""

fp = 'MWE.java'
with open( fp, 'w' ) as f:
    f.write( java_mwe )

javac = '{}/bin/javac'.format(os.environ[ 'JAVA_HOME' ])
proc = subprocess.run( 
    [ javac, '-cp', jnius_config.split_char.join( jnius_config.get_classpath() ), fp ],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)
if proc.returncode != 0:
    print ( proc.stderr )

from jnius import autoclass

MWE = autoclass('MWE')
mwe = MWE()
a = [1,2,3]
b = [1,2,3]
mwe.doSomething(a)
mwe.doSomething(a, b)

The output is (as expected):

One argument.
Two arguments.

If you have any example (that compiles without additional Java dependencies), please share!