Incorrect documentation for callbacks

Started by kenzierocks, December 30, 2014, 17:20:33

Previous topic - Next topic

kenzierocks

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:
Quotethey are functional interfaces by definition, so SAM conversions in Java 8 can naturally be applied on them.

kenzierocks

Oh, I have discovered the SAM interface of each callback. This might need to be made clearer in the documentation.

kenzierocks

Additionally, the SAM interfaces do not work. You cannot pass them to the callback areas.

SHC

They are working, I use them all the time. Here is a small example.

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

spasi

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.