https://kotlinlang.org logo
#announcements
Title
# announcements
p

poohbar

08/23/2017, 6:02 PM
Copy code
Button b2 = new Button();
b2.Click  += new RoutedEventHandler(Onb2Click);
g

groostav

08/23/2017, 9:50 PM
yeah, I actually like the += syntax a fair bit, since I think its pretty concise. What I want is for
Copy code
Button b2 = new Button();
b2.Click  += new RoutedEventHandler(Onb2Click);

b2.Click(ClickEvent()); //or b2.Click.fire(ClickEvent()) or whatever your syntax is
to be a compiler failure.
@bj0 out of curiosity what is your favourite event syntax?
b

bj0

08/23/2017, 11:13 PM
i don't mind the
+=
syntax, though it's not clear as just calling a function. I really don't like having to wrap functions in handler objects though. Luckily you don't actually have to do that
g

gildor

08/24/2017, 1:46 AM
This looks more clear for me. Button().click.addListener { /* your code */ } or Button().click.setListener { /* your code */ } Because you should somehow separate between cases when your API supports only one listener or any amount of listeners.
n

napperley

08/25/2017, 12:35 AM
Geoff - Would have changed the property name to reflect that multiple event handlers can be stored, eg b2.clickHandlers.
Using addListener and removeListener functions is the cumbersome Java way to manage event handlers, which adds unnecessary boilerplate. The Kotlinic way to manage event handlers is more readable/easier to follow.
2 Views