1
有人可以解释为什么下面的代码编译?传递非元组到(Int,Int)=>()编译,为什么?
我认为它不应该编译。
object RandomExperiments extends App{
def takeTuple(t:(Int,Int))=print (s"$t ${t._1}\n")
takeTuple(1,3) // this should not compile !!!
takeTuple (1,3) // this should not compile !!!
takeTuple((1,3))
takeTuple(((1,3)))
def takeTwoInts(i1:Int,i2:Int)=print (s"$i1 $i2\n")
takeTwoInts(1,2)
// takeTwoInts((1,2)) // does not compile , this is expected
}
(1,3) 1
(1,3) 1
(1,3) 1
(1,3) 1
1 2
这是Scala的自动几倍的“功能”。请参阅例如我的回答[此处](http://stackoverflow.com/a/42730285/334519)以进行一些讨论,并提供一个选项,您至少可以启用此结果以进行警告。 –
请参阅http://stackoverflow.com/questions/12806982/scala-type-parameter-being-inferred-to-tuple – Eric
谢谢,有趣的知道。 – jhegedus