https://kotlinlang.org logo
#announcements
Title
# announcements
g

groostav

09/27/2019, 9:22 PM
Hey guys, does anybody know how to use the fully qualified name to an extension function? eg
Copy code
package asdf

fun Any.doThing() = TODO()

//...
package main

//no import statements

fun outer(){
  42.doThing() //<-- auto import `asdf.dothing`? 
  //No! I want to write the fully-qualified invocation instead!

  asdf.doThing(42) //error
  42.asdf.doThing() //error
  42.`asdf.doThing`() //error
}
b

bbaldino

09/27/2019, 9:36 PM
why make it an extension function then?
s

Sam Schilling

09/27/2019, 9:42 PM
Don’t believe this is possible though would need someone from JB to confirm
r

Ruckus

09/27/2019, 9:56 PM
As far as I know, you can't do it. It's related to the issue where you can't call
super
of an overridden extension function in a class.
g

groostav

09/27/2019, 10:07 PM
why make it an extension function then?
IntelliJ Live templates. I remember reading that live templates you were supposed to fully qualify everything and let the user + IDE alt-enter to import things as appropriate. Its not really a big deal, it just means my live-template generates code that doesnt compile until a few more alt-enter's.
l

louiscad

09/27/2019, 11:21 PM
You can use an import alias (
import package.stuff as thing
)
2 Views