https://kotlinlang.org logo
Title
d

dumptruckman

05/21/2018, 4:20 AM
Is it possible to create extension functions that are only available in the context of a function's parameters?
s

Shawn

05/21/2018, 4:21 AM
uh, my first thought is no, but can you maybe share an example of how you’re thinking of using it?
d

dumptruckman

05/21/2018, 4:22 AM
like
something[+"name"]
where the unary plus is only available in the get function's parameter list
@Shawn
s

Shawn

05/21/2018, 4:26 AM
I guess I meant more like where the extension would be defined - what the other operand of unary + would be applied to in this context while also being used as a parameter
in any event I’m pretty certain you can’t define functions that are only exposed within the context of a function call
d

dumptruckman

05/21/2018, 4:27 AM
mmk
s

Shawn

05/21/2018, 4:27 AM
maybe a
get
with a different signature would be the better option
d

dumptruckman

05/21/2018, 4:28 AM
yeah i guess
i was trying to avoid that but i'm extending something with this get function that already has a get function that accepts a string
inline operator fun <reified T> ConfigurationSection.get(path: CharSequence): T
Is there some way to call that where it wouldn't be calling the
get(path:String): Any?
function?
s

Shawn

05/21/2018, 4:30 AM
hmm does the compiler currently complain about a platform declaration clash?
and does the other
get
also take a reified
T
?
d

dumptruckman

05/21/2018, 4:31 AM
No, it just goes for the original get
And no, it's a java method
val test = config["test"]
val test: Int = config["test"]
I'm trying to get the second one to call my function
config<Int>["test"]
isn't valid though
config.get<Int>("test")
works but defeats the point of this
s

Shawn

05/21/2018, 4:35 AM
the parameterized get seems to be your only option since the Kotlin grammar doesn’t seem to have a provision for types in bracketed
get
calls
d

dumptruckman

05/21/2018, 4:41 AM
hmm ok
thanks for your help
👍 1