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