avoid inheriting method in scala
inheritance, scala
Solution
scala> val x = new A with B { override def foo = super[A].foo }
x: A with B = $anon$1@4822f558
scala> x.foo
res0: java.lang.String = A.foo
scala> x.bar
res1: java.lang.String = B.bar
It is obviously not something you want to do too often.
Problem
The following code snippet ``` class A { def foo = "A.foo" } trait B { def foo = "B.foo" def bar = "B.bar" } val x = new A with B ``` does not compile because ``` error: overriding method foo in class A of type => java.lang.String; method foo in trait B of type => java.lang.String needs `override' modifier ``` However, my intention is define x so that: ``` x.foo => "A.foo" x.bar => "B.par" ``` That is, I only want x to inherit bar from B, but not foo. Is there a way in scala to achieve that?