Skip to content

Instantly share code, notes, and snippets.

@ademar111190
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save ademar111190/2e11683ba9df1644b194 to your computer and use it in GitHub Desktop.

Select an option

Save ademar111190/2e11683ba9df1644b194 to your computer and use it in GitHub Desktop.
One month with Kotlin: closure example
// Using Closure on Kotlin
button.setOnClickListener {
Thread {
// Amazing! Just 2 identations, 5 lines and 55 characters "lesser than a half of tweet"
}.start()
}
//------------------------------------------------------------------------------
// Using the nearest from Closure in Java 7
button.setOnClickListener(new View.onClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
// Hummmm... 4 identations, 11 lines and 207 characters "bigger than one tweet"
}
}).start();
}
});
@cy6erGn0m
Copy link

Kotlin's version could be simplified to

// Using Closure on Kotlin
button.setOnClickListener {
    thread {
        // Amazing! Just 2 identations, 5 lines and 55 characters "lesser than a half of tweet"
    }
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment