Home > Back-end >  Is there any difference in Kotlin between a capped type parameter extension function and a normal ex
Is there any difference in Kotlin between a capped type parameter extension function and a normal ex

Time:04-20

Is there any difference between these two?

fun <T : Parent> T.function() {}

vs.

fun Parent.function() {}

CodePudding user response:

As you wrote it - no.

It is important for function chaining:

fun <T : Parent> T.function():T { return this } //allows chaining

vs.

fun Parent.function():Parent { return this } //casts to base class
  • Related