The Artima Developer Community
Sponsored Link

Programming in Scala Forum
extending multiple traits.

1 reply on 1 page. Most recent reply: Feb 2, 2008 1:21 AM by Eric Willigers

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
jeroen dijkmeijer

Posts: 6
Nickname: 53764
Registered: Jan, 2008

extending multiple traits. Posted: Feb 1, 2008 6:47 AM
Reply to this message Reply
Advertisement
I'm currenlye reading the book, its well written and a pleasure to read. I do have a question though on page 74 (not sure which version) the book says:
In Java, a class can implement zero to many interfaces. Similarly in Scala, a class can extend zero to many traits;
But how you can implement multiple traits is not discussed. Or is the "with mix in" meant, I dont see that as a multiple implements.

regards,
Jeroen.


Eric Willigers

Posts: 8
Nickname: ewilligers
Registered: Dec, 2007

Re: extending multiple traits. Posted: Feb 2, 2008 1:21 AM
Reply to this message Reply
In

trait A { def f = 42 }
trait B { def g = false }
trait C { def h = "answer" }
class ABC extends A with B with C {}

you can optionally change A to being a class, and you can also optionally change ABC to being a trait or object.

So we use "extends" before the first class or trait that we wish to inherit from, and if we wish to inherit from additional traits, we use "with" before each of them.

Flat View: This topic has 1 reply on 1 page
Topic: Page  112( Error) Previous Topic   Next Topic Topic: unit value: () or {}

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use