1
使用SBT疯疯癫癫的插件:斯卡拉Dotty联盟类型?
addSbtPlugin("com.felixmulder" % "sbt-dotty" % "0.1.9")
和运行sbt console
,我尝试新的联合类型的功能:
Starting dotty interpreter...
Welcome to Scala.next (pre-alpha, git-hash: 606e36b) (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class A(val x: Int, y: Double)
defined class A
scala> case class B(val x: Int, y: String)
defined class B
scala> def getX(o: A | B): Int = o.x
-- [E008] Member Not Found Error: <console> ------------------------------------
8 |def getX(o: A | B): Int = o.x
| ^^^
| value `x` is not a member of (A | B)(o)
为什么不这项工作?我使用联合类型是否错误?这只是没有工作?
那个DarkDimius幻灯片是我混乱的根源。谢谢。 – clay