Extension functions with conflicting names

What happens when an extension function has the same name as a member function?

The Worker class has a function work(): String and a private function rest(): String. We also have two extension functions with the same signature, work and rest:

class Worker {   fun work() = "*working hard*"   private fun rest() = "*resting*"}fun Worker.work() = "*not working so hard*"fun <T> Worker.work(t:T) = "*working on $t*"fun Worker.rest() = "*playing video games*"

Having extension functions with the same signature isn't a compilation error, but a warning: Extension is shadowed by a member: public final fun work(): String

It is legal to declare a function with the same signature as a member function, but the member ...

Get Functional Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.