Last active
April 2, 2023 10:13
-
-
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/428285e9dc84436a0f5c05846dfa7bf7a001cebc
This file contains 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.1.1" | |
// ----------------------------------------------------- | |
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