Last active
May 25, 2024 10: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/10b41cf96bcb8966d45d651aaaabdb98ac73dbfe
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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// 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