我试图使用表达式来映射选项,但我只想匹配如果选项的内容是特定类型。我想会的工作是这样的:是否可以在Scala中为表达式匹配类型?
for {
vcs: Mercurial <- maybeVcs
} yield vcs
但是,这会产生以下编译错误:
<console>:76: error: type mismatch;
found : sbtrelease.Mercurial => sbtrelease.Mercurial
required: sbtrelease.Vcs => ?
vcs: Mercurial <- get (releaseVcs in Compile)
^
是否有可能模式匹配的类型的表达?
的[为什么Scala的模式MACHING不为类型匹配回路工作?]可能的复制(http://stackoverflow.com/questions/11394034/why-scalas-pattern-maching-does-not-for-for-loops-for-type-matching) –