December 2017
Intermediate to advanced
260 pages
7h 34m
English
Oftentimes, we need a function to notify us when something gets done. We prefer callbacks in JavaScript. To write a click event for a button, a typical JavaScript code could look like the following:
$("#btn_submit").click(function() { alert("Submit Button Clicked"); });
With Kotlin, it's simple. Kotlin uses the Lambda function to achieve this. For the LoginWindow class, we have passed a callback as a constructor parameter. In the LoginWindow class (val callback: (String) -> Unit), the class header specifies that the constructor will take a callback as a parameter, which will return a string when invoked.
To pass a callback, we will write the following line of code:
callback(nickName)
To consume a callback, we will ...
Read now
Unlock full access