Last active
April 2, 2023 10:10
-
-
Save dacr/d13d2da454dd1267ba9fbaaca85e6506 to your computer and use it in GitHub Desktop.
scala3 feature examples - anonymous class inference / published by https://github.com/dacr/code-examples-manager #23c62324-a693-4395-97ed-e5040e976d71/d80c7ed07648aea40ef5995c164ae132588fc92a
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 - anonymous class inference | |
// 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 : 23c62324-a693-4395-97ed-e5040e976d71 | |
// created-on : 2021-04-21T13:59:22+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
//> using scala "3.1.1" | |
trait Message { | |
val text: String | |
} | |
def dumpMessage(message:Message) = println(message.text) | |
// --------------------------------------------------------------- | |
abstract class Person { | |
val name: String | |
} | |
def sayHello(person:Person) = println("Hello "+person.name) | |
// --------------------------------------------------------------- | |
trait MutableStuff { | |
var message: String="" | |
} | |
def someStuff(stuff:MutableStuff) = println(stuff.message) | |
// --------------------------------------------------------------- | |
@main def go():Unit = { | |
dumpMessage(new {val text="Bouh!"}) | |
sayHello(new {val name="John"}) | |
someStuff(new {message="hummm?"}) // When the field is a var with an already defined and so overrable value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment