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)

なぜこれが機能しないのですか?ユニオン型を間違って使用していますか? これはまだ機能していませんか?

4

1 に答える 1