为什么这个编译:
def foo() : Iterable[URI] = {
Some("")
.map(URI.create)
}
在implicit conversion called option2Iterable
上直接定义了Option
,它将所有Option[A]
转换为零或一个元素的Iterable[A]
。
一个更短的代码片段,演示了这种有些意外的行为如下:
(Option(42): Iterable[Int])
它将悄然将Option
转换为List
,在这种情况下生产List(42)
。