Callable function reference literals? (double colon :: syntax)


#1

The Kotlin web demo contains an example where a static function is referred by a double colon (Callable references / reference to a function):  ::isOdd

I however cannot find any mention to this in the docs. When creating a Swing application, I can write:

  button.addActionListener { (e) -> buttonClick() };

Which is really nice. I have these two methods:

  fun buttonClick() = System.out.println(“hello world”);
  fun buttonClick2(e : ActionEvent) = System.out.println(“xx”);


It’d be even nicer for me if I could just write something like:
  button.addActionListener { this::buttonClick };

This does not compile, but if I just write “::buttonClick” or “::buttonClick2”, it compiles but the event handler is not invoked.

Am I trying to do something I should not?
Thanks in advance.


#2

It's something that's planned but not yet implemented. Please subscribe to this issue to receive updates


#3

Oh, thanks for the link.