我在如此定义的lwjgl java中有functionalInterface
:
@FunctionalInterface
@NativeType("GLFWkeyfun")
public interface GLFWKeyCallbackI extends CallbackI.V {
String SIGNATURE = "(piiii)v";
@Override
default String getSignature() { return SIGNATURE; }
@Override
default void callback(long args) {
invoke(
dcbArgPointer(args),
dcbArgInt(args),
dcbArgInt(args),
dcbArgInt(args),
dcbArgInt(args)
);
}
/**
* Will be called when a key is pressed, repeated or released.
*
* @param window the window that received the event
* @param key the keyboard key that was pressed or released
* @param scancode the system-specific scancode of the key
* @param action the key action. One of:<br><table><tr><td>{@link GLFW#GLFW_PRESS PRESS}</td><td>{@link GLFW#GLFW_RELEASE RELEASE}</td><td>{@link GLFW#GLFW_REPEAT REPEAT}</td></tr></table>
* @param mods bitfield describing which modifiers keys were held down
*/
void invoke(@NativeType("GLFWwindow *") long window, int key, int scancode, int action, int mods);
}
我有一个相应的kotlin:
typealias KeyCallbackT = (key: Int, scanCode: Int, action: Int, mods: Int) -> Unit
我失踪的大事(因为它很容易出错而困扰我),每当我开始输入GLFWKeyCallbackI
时,我就可以选择相应的代码自动完成选项,它将自动写入所有已定义的参数:
GLFWKeyCallbackI { window, key, scanCode, action, mods ->
像这样:
但我与typealias
当然,我有其他多种类似的情况,如果我可以获得相同的自动完成,那就很好了