1

Possible Duplicate:
In Scala how can I advise my own methods?

Assume:

trait SomeAbstractTrait {
    val transform : Int => Int
}

Why does the following work:

new SomeClass() with SomeTrait with SomeAbstractTrait {
   val transform : Int => Int = (x) => x*2
}

while

new SomeClass() with SomeAbstractTrait {
   val transform : Int => Int = (x) => x*2
} with SomeTrait 

does not?

Having to declare traits with a single abstract function object before I can use them is a bit annoying and since the first version works I assume I just got the syntax wrong?

Community
  • 1
  • 1
Voo
  • 29,040
  • 11
  • 82
  • 156
  • It's unclear what you're asking. What are you trying to do? And what makes you think that the second bit of code is preferable to the first? – dhg May 20 '12 at 18:46
  • @dhg I'm trying to avoid having to write `trait X1 extends SomeAbstractTrait {}` and then use `X1` since all those implementations of SomeAbstractTrait are all only used once. Since the sequence of traits does matter the first one isn't equivalent to the second one (if the second one would compile and do the obvious), so it's not really about "preferable". – Voo May 20 '12 at 18:49
  • And `new SomeClass() with SomeAbstractTrait with SomeTrait` isn't what you want? Maybe you could edit your question to explain more completely. For example, put in a full, working example. Also you reference a "abstract function object", but there are no functions shown. – dhg May 20 '12 at 18:55
  • @dhg I wanted to keep it short, but since that's causing confusion I've added the declaration for `SomeAbstractTraint` and the actual implementation of it. `with SomeAbstractTrait` does not work as it's abstract and need its implementation to be useful. – Voo May 20 '12 at 19:00
  • @Owen Yes seems to be the same, too bad that it doesn't work. If you post that as an answer I'll accept it – Voo May 20 '12 at 19:03
  • 2
    Actually I think this would be a duplicate question. – Owen May 20 '12 at 19:07
  • 1
    @Owen Right you are, completely forgot about that. Luckily one can vote to close their own question. – Voo May 20 '12 at 19:10

0 Answers0