Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Constants are not properly passed from Java to Python when using interfaces #140

@Dr-Irv

Description

@Dr-Irv

Consider the following example that is modified from jpy/doc/intro.rst
Assuming we have a Java interface PlugIn.java ::

    public interface PlugIn {
        String[] process(String arg);
        void setVal(int val);
        boolean check1234();
    }

and a Python implementation bibo_plugin.py ::

    class BiboPlugIn:
        def process(self, arg):
            return arg.split();
        def setVal(self, val):
            self._val = val
        def check1234(self):
            return self._val == 1234

then we can call the Python code from Java as follows ::

    // Import the Python module
    PyModule plugInModule = PyLib.importModule("bibo_plugin");

    // Call the Python class to instantiate an object
    PyObject plugInObj = plugInClass.call("BiboPlugin");

    // Create a Java proxy object for the Python object
    PlugIn plugIn = plugInObj.createProxy(PlugIn.class);

    String[] result = plugIn.process('Abcdefghi jkl mnopqr stuv wxy z');

    plugIn.setVal(1234);
    if plugIn.check1234() {
        System.out.println("it is equal");
    }
    else {
        System.out.println("it is not equal"):
    }

If you run the above snippet, you will get it is not equal, which is incorrect.

What is happening is that the fundamental types are not being received into the correct types in Python.

I have a fix for this, which I will submit in a moment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions