-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scala 2 Book migration - Scala Classes #3128
base: main
Are you sure you want to change the base?
Conversation
{% tabs traits_7 %} | ||
{% tab 'Scala 2 and 3' %} | ||
```scala | ||
val s = new MyService("ComposedService") with GreetingService with TranslationService |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intuitively, after seeing the syntax used above, someone could expect this to be defined in Scala 3 as:
val s = MyService("ComposedService") with GreetingService, TranslationService
It seems like only the Scala 2 syntax is accepted, though.
{% tabs fun-partial-5 class=tabs-scala-version%} | ||
{% tab 'Scala 2' %} | ||
```scala | ||
doubledOdds.applyOrElse(4, (i: Int) => i + 1) // 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small fix which I omitted last time somehow.
### Overriding an implemented method | ||
|
||
A class can also override a method that is defined in a trait. Here is an example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This covers both Overriding an implemented method
and Mixing in multiple traits that have behaviors
parts from the Scala 2 version.
No description provided.