Last active
February 3, 2026 20:18
-
-
Save dacr/69c0e3f645a2cdaa89bc22c2d6af5679 to your computer and use it in GitHub Desktop.
scala3 feature examples - trait parameters / published by https://github.com/dacr/code-examples-manager #9ddc2563-f5a4-461f-b137-8d57c3be914a/ebab8e2eb934e6abe721818cafe51242f6d9eaf4
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 - trait parameters | |
| // keywords : scala3, tutorial, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 9ddc2563-f5a4-461f-b137-8d57c3be914a | |
| // created-on : 2021-11-17T18:46:03+01:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| //> using scala "3.4.2" | |
| // ----------------------------------------------------- | |
| trait HelloTrait1(name:String): | |
| def message = s"Hello $name" | |
| case class Hello1() extends HelloTrait1("joe") | |
| // ----------------------------------------------------- | |
| trait HelloTrait2(val name:String): | |
| def message = s"Hello $name" | |
| case class Hello2() extends HelloTrait2("paul") | |
| // ----------------------------------------------------- | |
| @main def go():Unit = | |
| println(Hello1().message) | |
| println(Hello2().message + Hello2().name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment