• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

Java Equivalent to C++ Function Pointers

C++ to Java Converter converts C++ function pointer typedefs to Java functional interfaces.

Here's an example using two different formats for function pointer typedefs:

C++ Java
class TestFunctionPointers
{
    typedef void(TestFunctionPointers::*Foo1)();
    using Foo2 = void(TestFunctionPointers::*)(); //C++11 syntax

    void method()
    {
        Foo1 TestPtr1 = &TestFunctionPointers::matchedMethod;
        (this->*TestPtr1)();
        Foo2 TestPtr2 = &TestFunctionPointers::matchedMethod;
        (this->*TestPtr2)();
    }
    void matchedMethod()
    {
    }
};
public class TestFunctionPointers
{
    @FunctionalInterface
    private interface Foo1
    {
        void invoke();
    }
    @FunctionalInterface
    private interface Foo2
    {
        void invoke();
    }

    private void method()
    {
        Foo1 TestPtr1 = () -> this.matchedMethod();
        TestPtr1.invoke();

        Foo2 TestPtr2 = () -> this.matchedMethod();
        TestPtr2.invoke();
    }
    private void matchedMethod()
    {
    }
}


Use C++ to Java Converter to convert from C++ to Java.     

Additional resource: Java and C++ Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.