Reputation: 21
class DATA<T>
public fun <T> add1(t1:T,t2:T): List<T> = listOf(t1, t2)
public infix fun <T> T.add2(t2:T): List<T> = listOf(this, t2)
fun printData(list: List<DATA<String>>) {
println("Hello World!")
}
fun main(args: Array<String>) {
printData( add1(DATA(), DATA()) )
printData( DATA() add2 DATA()) //why this line can not compile?
}
As the above code shows, when I using infix function, the type can't be deduced properly, and produced a compile error, why kotlin does not support this?
Upvotes: 0
Views: 35