Consider the following scenario: I have a class Test
class Test() {
infix fun say(msg: String) = println(msg)
}
and a main method
fun main(args: Array<String>) {
val test = Test()
test say "Hello World!" //Works
with(test) {
say "Goodbye World!" //Does not work
say("Hello again!") //Works
}
}
As you can see I'm testing out the infix notation. Considering with(...)
allows you to work with the object passed as parameter in the with block
without having to access its members through the dot notation, I would expect the infix notation to work like I show in my example above.
Unfortunately this does not work, is there a reason why this does not work? Is it a bug or simply a limitation? Or perhaps I am not interpreting the with(...)
function correctly?