Last active
May 25, 2024 10:20
-
-
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/f147d97cab064ad2433a9bf2f589f9799a6a7361
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 - 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.4.2" | |
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