Search code examples
javakotlinconstructorcallbackfunctional-interface

How do I call this constuctor in java?


I have a library (.aar) file which i imported in java. The class is LSPatch which has a constructor.

public final class LSPatch public constructor(options: org.json.JSONObject, onDiscovery: (org.json.JSONObject) -> kotlin.Unit, onData: (org.json.JSONObject) -> kotlin.Unit, onStatus: (org.json.JSONObject) -> kotlin.Unit) {....}

Now I have no idea how to call this constuctor in java source code when I need to create an object of Class 'LSPatch'. Like i want to create

LSPatch lspatch=new LSPatch(...);

When i try to do so it shows: enter image description here Am not able to relate it to java. Can anybody please help me. Just give me an idea what are those parameters and how to call the constructor practically.


Solution

  • You can use lambdas in Java for 2nd, 3rd and 4th parameters:

    LSPatch lspatch = new LSPatch(
                new JSONObject(),
                jsonObject -> {
                    // do your stuff
                    return null;
                },
                jsonObject -> {
                    // do your stuff
                    return null;
                },
                jsonObject -> {
                    // do your stuff
                    return null;
                }
    );