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

Benoît

06/22/2019, 2:23 AM
Just out of curiosity, why is this a thing ?
Copy code
infix fun <T> Any.go(block: (T) -> Unit) {

    }

    fun main() {
        // Valid
        "".go<String> {

        }
        // Invalid
        "" go <String> {

        }
    }
p

Pavlo Liapota

06/22/2019, 6:27 AM
If you want to use infix call you can write:
Copy code
"" go { x: String ->

}
👍 1
b

Benoît

06/22/2019, 11:58 AM
Indeed, but what about this?
Copy code
infix fun <T> Any.go(block: T.() -> Unit) {

}
s

Shawn

06/22/2019, 1:22 PM
What about it? What exactly are you trying to do?
You can maybe make this a bit more convenient to write with a definition like this
Copy code
infix fun <T : Any> T.go(block: (T) -> Unit { }

"" go {

}
b

Benoît

06/24/2019, 2:56 PM
I'm not trying to do anything particular I was just wondering how to specify the generic type on an infix function
2 Views