Convert Java to Kotlin (With a function as an argument)

989 views kotlin
-1

I want this code in Kotlin:

public class LobbySwitcherGui extends AGUI {

public LobbySwitcherGui() {
    super(27, "someTitle");

    setItem(0, new ItemStack(Material.NETHER_STAR), player -> {
        player.sendMessage("Some message");
    });
}

}

but if I convert it in IntellIJ its doesnt work for me.

class LobbySwitcherGui : AGUI(27, "someTitle") {
init {
    setItem(0, ItemStack(Material.NETHER_STAR), { player -> player.sendMessage("Some message") })
}

}

The last Argument istn working and I cant fix it..

AGUI class is this: https://ghostbin.com/paste/gjdzo

answered question

1 Answer

6

kotlin can create Runnables and Function, BiFunction, etc that way.. you seem to create something called a YourGUIAction, check if that might be replaced with action: (Player) -> Unit or in general (ArgumentTypes) -> ReturnType

posted this

Have an answer?

JD

Please login first before posting an answer.