Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

A question about Kotlin extension functions resolution

The code below :

package experimental

import experimental.AnObject.f

interface AnInterface {
    fun String.a() = "[AnInterface] $this"
}

object AnObject {
    fun AnInterface.f(str: String) = "[AnObject]" + str.a()
}

class AnInterfaceImpl  : AnInterface

fun main() {
    println( AnInterfaceImpl().f("hi") ) 
}

prints [AnObject][AnInterface] hi

My question is, how does the call to AnInterfaceImpl().f ends up resolved to the extension function in AnObject

question from:https://stackoverflow.com/questions/65643088/a-question-about-kotlin-extension-functions-resolution

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...