« Return to Thread: [scala] override optional when superclass method is abstract

Re: [scala] override optional when superclass method is abstract

by Jon Pretty :: Rate this Message:

Reply to Author | View in Thread

Hi Paul,

Paul Phillips wrote:
> abstract class A { def foo:String }
> class B extends A { def foo:String = "hi" }
> class C extends A { override def foo:String = "bye" }
>
> Scala is cool with it whether or not you specify override in this
> (common) situation.  I think it should require one way or the other,
> else the inevitably inconsistent subclasses emit needless noise.

No, this does actually serve a purpose, though not one which comes up often.  Consider the
following diamond inheritance:

   trait A { def foo : Int }
   trait B extends A { def foo = 10 }
   trait C extends A { def foo = 20 }
   trait D extends B with C

This - in particular trait D - won't compile.  But if we write

   trait A { def foo : Int }
   trait B extends A { def foo = 10 }
   trait C extends A { override def foo = 20 }
   trait D extends B with C

then it will.

Cheers,
Jon

--
Jon Pretty | Sygneca Ltd

 « Return to Thread: [scala] override optional when superclass method is abstract

LightInTheBox - Buy quality products at wholesale price!