This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Accessing val in parent trait

2 replies
boisvert
Joined: 2009-11-11,
User offline. Last seen 38 weeks 5 days ago.
Is is possible to access a val in a parent trait?  Here's roughly what I like to do,
trait Parent {  val foo = "foo"}
class Child extends Parent {   override val foo = if (something) "bar" else Parent.this.foo}
... which doesn't compile.  Any other way to do this?
alex
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Accessing val in parent trait

On Mon, Nov 08, 2010 at 11:54:19AM -0800, Alex Boisvert wrote:
> Is is possible to access a val in a parent trait? Here's roughly what
> I like to do,

https://lampsvn.epfl.ch/trac/scala/ticket/1938
"traits should be able to call super on fields"

boisvert
Joined: 2009-11-11,
User offline. Last seen 38 weeks 5 days ago.
Re: Accessing val in parent trait
Thanks Jason & Paul.   I'll go with a def for now.
alex

On Mon, Nov 8, 2010 at 12:49 PM, Paul Phillips <paulp@improving.org> wrote:
On Mon, Nov 08, 2010 at 11:54:19AM -0800, Alex Boisvert wrote:
> Is is possible to access a val in a parent trait?  Here's roughly what
> I like to do,

https://lampsvn.epfl.ch/trac/scala/ticket/1938
"traits should be able to call super on fields"

--
Paul Phillips      | Simplicity and elegance are unpopular because
Apatheist          | they require hard work and discipline to achieve
Empiricist         | and education to be appreciated.
pp: i haul pills   |     -- Dijkstra

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland