Kotlin setOnClickListener using method reference not working

Kotlin setOnClickListener using method reference not working

I tried to use method reference the same way as in Java:

I tried to use method reference the same way as in Java:

button.setOnClickListener(this::clickListener);

Using Kotlin:

button.setOnClickListener {this::clickListener}

However this doesn't work in Kotlin, the solution is to actually invoke the function withing the labmda expression:

button.setOnClickListener {clickListener()}

Why Kotlin doesn't accept the method reference in this case? Isn't the same principle as with Java?

java android kotlin

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

Top Android Projects with Source Code

Android projects with source code - Work on real-time android projects. We’ll start project ideas from beginners level and later move to advance projects.

Kotlin Coroutines on Android - How to use Coroutines on Android

Coroutines are a Kotlin feature that convert async callbacks for long-running tasks, such as database or network access, into sequential code. This Kotlin Coroutines tutorial will show you how to use coroutines on Android, and how the new androidx-concurrent library makes it easy to use them to get things off the main thread. You'll also learn how the new library helps coroutines work with Architecture Components. This session also covers coroutine patterns, best practices, and even how to test coroutines!

What's New in Java 19: The end of Kotlin?

What's New in Java 19: The end of Kotlin? Will Kotlin still have a place in the JVM language ecosystem in a few years? This tutorial will compare and contrast how the two languages approach solving the same problems of today's Java. We'll peer a few years into the future to see where both languages are headed and determine whether we still need a Kotlin

Build A Simple Application For Android Using Kotlin And Android Studio

Build A Simple Application For Android Using Kotlin And Android Studio - We will create a simple calculator android application which would be able to perform simple arithmetic calculations like…

Android Menu - Steps to implement Menu in Android - DataFlair

Implement Android Menu in your application - Provide functionality to your application and make it user friendly. Also, Learn its types and implementation.