Hello Guest

Incorrect documentation for callbacks

  • 4 Replies
  • 2903 Views
Incorrect documentation for callbacks
« on: December 30, 2014, 17:20:33 »
Callbacks are listed as functional interfaces in the Binding section, when they are actually abstract classes. An abstract class with one abstract method is not a functional interface.

From 1.5 Bindings FAQ:
Quote
they are functional interfaces by definition, so SAM conversions in Java 8 can naturally be applied on them.

Re: Incorrect documentation for callbacks
« Reply #1 on: December 30, 2014, 17:24:32 »
Oh, I have discovered the SAM interface of each callback. This might need to be made clearer in the documentation.

Re: Incorrect documentation for callbacks
« Reply #2 on: December 30, 2014, 17:29:07 »
Additionally, the SAM interfaces do not work. You cannot pass them to the callback areas.

*

Offline SHC

  • **
  • 94
    • GoHarsha.com
Re: Incorrect documentation for callbacks
« Reply #3 on: December 30, 2014, 17:42:52 »
They are working, I use them all the time. Here is a small example.

Code: [Select]
private void myKeyCallback(long window, int key, int scancode, int action, int mods)
{
    // Do something with the input here
}

GLFWKeyCallback keyCallback = GLFWKeyCallback(this::myKeyCallback);
glfwSetKeyCallback(keyCallback);
This is how you should use it. If you are still in confusion, I had written a tutorial here

*

Offline spasi

  • *****
  • 2169
    • WebHotelier
Re: Incorrect documentation for callbacks
« Reply #4 on: December 30, 2014, 17:55:12 »
Hey kenzierocks,

The Bindings FAQ has not been updated with the latest changes. Specifically, the information on callbacks and structs is out of date.

Callbacks are indeed abstract classes now, but as SHC explained, there's a relatively clean workaround for using lambdas and method references. This was originally explained in this post.