1

I have a class in java:

public class MyClass{
    public String a=null;
    public String b=null;
    public String c=null;
    public String d=null;
    public static String testMyClass() {
        //my method instruction using the attributes a,b,c and d
    }

The trouble is that MyClass attributes must be received from python to be able to use the method testMyClass. So is it possible to instantiate a java class from python and after send it back to java using py4j? Anyone can show how to make it if it is possible? Or have another alternative?

1 Answer 1

2

I don't think that is possible unless someone knows of a "bridge" utility between Java and Python.

However, you may do this:

  1. Create a JSON in the Python script in a structure that matches that of MyClass
  2. Receive it in your Java method and deserialize the JSON into an instance of MyClass using Jackson or some JSON tool.

Your next problem will be the communication between you Java process and Python process. For that, see if this StackOverflow question helps: Passing data from Java process to a python script

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.