Re: [scala] override optional when superclass method is abstract
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