Skip to content

Rewrote traits tour #713

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

Merged
merged 1 commit into from
May 11, 2017
Merged

Rewrote traits tour #713

merged 1 commit into from
May 11, 2017

Conversation

travissarles
Copy link
Contributor

No description provided.

Similar to interfaces in Java, traits are used to define object types by specifying the signature of the supported methods. Like in Java 8, Scala allows traits to be partially implemented; i.e. it is possible to define default implementations for some methods. In contrast to classes, traits may not have constructor parameters.
Here is an example:

Traits are used to share interfaces and fields between classes. They are similar Java 8's interfaces. Classes and objects can extends traits but traits cannot be instantiated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar -> similar to

can extends -> can extend

@soronpo
Copy link
Contributor

soronpo commented Feb 25, 2017

Thought (I have no solid opinion on this): Shouldn't examples in Scala Tour focus more on functional/immutable code, than imperative/mutable code?

I think there should be an example that demonstrates inheritance from more than one trait (or else, why not just use an abstract class).
I wonder if there should be a mention that traits cannot accept parameters. That of course changes in Dotty, and there currently is a SIP that may change that for Scalac as well.

@travissarles travissarles mentioned this pull request Mar 17, 2017
33 tasks
@travissarles travissarles merged commit 1692b5f into scala:master May 11, 2017
@SethTisue
Copy link
Member

I think there should be an example that demonstrates inheritance from more than one trait

the next section of the tour is http://docs.scala-lang.org/tutorials/tour/mixin-class-composition.html, but a PR adding a forward reference would be welcome. (I think it would even be reasonable to merge the two pages.)

I agree an immutable example would be preferable, but this PR doesn't move backwards on that, at least. a separate PR with a better example would be welcome

@travissarles travissarles deleted the traits branch June 5, 2017 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants