lxw
lxw

Reputation: 21

why kotin can not deduce a type when using infix?

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

Answers (0)

Related Questions