Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created August 22, 2021 10:24
Show Gist options
  • Save xuwei-k/8fdc0c1adf2d6b790d440f47be792287 to your computer and use it in GitHub Desktop.
Save xuwei-k/8fdc0c1adf2d6b790d440f47be792287 to your computer and use it in GitHub Desktop.
object Main {
def head[A](list: List[A]): A = list.head
def x1: List[Int] | List[String] = List(3)
// この変換は可能。逆の変換は無理
def x2: List[Int | String] = x1
def x3 = head(x1)
def x4 = head(x2)
x3 : (Int | String) // Matchableになってしまってコンパイルエラー
x4 : (Int | String) // これは成功
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment