Methods syntax

Trailing closures

Block after a call binds to the last parameter.

Button(text = "Hi") { ... } passes the block as a lambda for the trailing parameter. When that parameter is Supplier<[T]>, the block becomes a result builder collecting child expressions into a list.

Affogato

example.aff
Button(text = "Click me") {
    println("clicked")
}

Panel {
    Label(text = "Title")
    Button(text = "OK") { submit() }
}

Generated Java

Example.java
Button(text = "Click me", () -> {
    System.out.println("clicked");
});

Panel(List.of(
    Label(text = "Title"),
    Button(text = "OK", () -> submit())
));

Related

See also

← All keywords