JavaFunction

Contents

JavaFunction#

template<typename R>
FunctionHandler<JavaFunctionHandler<R>> YR::JavaFunction(const std::string &className, const std::string &functionName)#

Create a FunctionHandler for invoking a Java function from C++.

// Java code:
package com.example;

public class YrlibHandler {
public static class MyYRApp {
    public static int add_one(int x) {
            return x + 1;
        }
    }
}

// C++ code:
int main(void) {
    YR::Config conf;
    YR::Init(conf);
    auto ref = YR::JavaFunction<int>("com.example.YrlibHandler$MyYRApp", "add_one").Invoke(1);
    int res = *YR::Get(ref);   // get 2
    return 0;
}

Template Parameters:

R – The return type of the Java function.

Parameters:
  • className – The fully qualified class name of the Java function, including package name. If the class is an inner static class, use ‘$’ to connect the outer class and inner class.

  • functionName – The name of the Java function to invoke.

Returns:

A FunctionHandler object that can be used to execute the Java function. The return type can be accessed through the JavaFunctionHandler template class.