Where as this doesn't.
# announcements
c
Where as this doesn't.
🧵 3
d
because the fun is declared inside your
Test
class
👆 5
if you would move your code from
main
to eg.
init
of your Test class it would work
c
You made me realize that, I need to revisit my basics. Thanks a lot.
c
Copy code
package com.example

class Test {
   operator fun String.get(range: IntRange) = substring(range)
}

class Test2 {
   companion object {
       operator fun String.get(range: IntRange) = substring(range)
   }
}

fun main() {
   val x = "test"
   val y = with(Test()) { x[2..3] }
   val z = with(Test2) { x[2..3]}
}
😎 2
t
is it possible to call
get
without
with
or similar? i do understand the result of the call but i can't figure out how i would explicitly write it...
Test().get()
doesn't work.
Test()."test"[]
doesn't even make any sense...
c
No,
get
here is double scoped.
t
ok thx