Is there a way to (locally) decorate an operator f...
# announcements
p
Is there a way to (locally) decorate an operator fun to take precedence over a builtin on the class? I'm writing test cases where overloading
get
makes sense, but some of the data I have to pass in are arrays. I can manually 'up' cast to Any, but I'm curious if there's any other possibility.
n
Just curious, why do you want to overload get so badly instead of using a named extension function?
e
a wrapper type may also be an option to consider
p
The thing that I'm testing is
thing[arg, arg]
so by overloading
get
I can write the test case (in Kotlin) and it looks exactly like the real case (in proprietary DSL)
e
you can overload that just fine, the signature is different than built-in
get
p
Sorry - variable number of args, so I have to overload
get(arg)
and
get(arg, arg)
- you're right that the latter 'just works'
e
I'd go with wrapper types for your DSL, then.
1
y
If you need to go super evil though, you could use
@kotlin.internal.HidesMembers
but you need to shadow that annotation using the instructions provided here
e
I've done that before with using a special sourceSet and adding to
compileOnly
. seems quite dangerous here, especially since OP (presumably) still needs some way to call the original
get
method…