Last active
February 3, 2026 20:24
-
-
Save dacr/4b10cd395025dde86b350a6e90f28678 to your computer and use it in GitHub Desktop.
scala3 feature examples - literal types / published by https://github.com/dacr/code-examples-manager #4335490b-72fe-46b6-95cf-7a84023569f6/8fa38f638d241e891ca32ae9ae1fd3df375ea737
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : scala3 feature examples - literal types | |
| // keywords : scala3, tutorial | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 4335490b-72fe-46b6-95cf-7a84023569f6 | |
| // created-on : 2021-03-25T11:22:13+01:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| //> using scala "3.4.2" | |
| val pi: 3.14157 = 3.14157 | |
| val _: 3.14157 = 3.14 // compile error ! | |
| val choice0: 1|2|3 = 1 | |
| val choice1: 1|2|3 = 4 // compile error ! | |
| val choice2: Option["A"|"B"] = None | |
| val choice3: Option["A"|"B"] = Some("A") | |
| val choice4: Option["A"|"B"] = Some("C") // compile error ! | |
| type Choice="A"|"B"|"C" | |
| val myChoice:Choice = "A" | |
| val myChoice:Choice = "D" // compile error ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment