Tangible Software Solutions

The Most Trusted Name in Source Code Conversion

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++:

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()
   {
   }
};

Java:

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()
   {
   }
}

If you need to convert from C++ to Java and you are depending on the results being reliable and accurate, then you will want to have C++ to Java Converter, the best C++ to Java converter, at your fingertips.

Copyright © 1997 - 2017 Tangible Software Solutions Inc.