Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I quickly tried it out, but could quite make it work using an object. There I had to use draw(ball) instead of draw ball, as you wanted:</p> <p><pre><code> Welcome to Scala version 2.8.0.RC2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).</p> <p>scala> trait Drawable{def doSomething} defined trait Drawable</p> <p>scala> object Draw {<br> def draw(d:Drawable) = d.doSomething } defined module Draw</p> <p>scala> val ball = new Drawable{def doSomething = println("doing ball")} ball: java.lang.Object with Drawable = $anon$1@3a4ba4d6</p> <p>scala> import Draw._ import Draw._</p> <p>scala> draw ball :11: error: missing arguments for method draw in object Draw; follow this method with `_' if you want to treat it as a partially applied function draw ball ^</p> <p>scala> draw(ball) doing ball </pre></code></p> <p>However by defining Draw as a class, it did work:</p> <p><pre><code> scala> trait Drawable{def doSomething: Unit} defined trait Drawable</p> <p>scala> class Draw {<br> def draw(d:Drawable) = d.doSomething } defined class Draw</p> <p>scala> </p> <p>scala> val ball = new Drawable{def doSomething = println("doing ball")} ball: java.lang.Object with Drawable = $anon$1@36a06816</p> <p>scala> val d = new Draw d: Draw = Draw@7194f467</p> <p>scala> d draw ball doing ball </pre></code></p> <p>I'm not completely sure why this doesn't work the same way with an object, might be a bug or perhaps that's specified behaviour. However I didn't have the time to look it up at the moment.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload