scala override methods in child object of class
New to scala and can't seem to find a reference on this situation.
I'm trying to override some methods on scala.swing.TabbedPane.pages: The definition of this class is:
class TabbedPane extends Component with Publisher {
object pages extends BufferWrapper[Page] {
def +=
}
}
I can't figure out the syntax for overriding any method in the internal pages object. Is this possible with scala?
Thanks.
EDIT: To make this question clearer.
class CloseableTabbedPane ex开发者_高级运维tends TabbedPane{
}
val pane = new CloseableTabbedPane;
pane.pages += new CloseablePage;
I need to override the method pane.pages += to accept a CloseablePage with an icon.
In the normal case of overriding a method in a class:
scala> class Foo { def foo : String = "Foo" }
defined class Foo
scala> class Bar extends Foo { override def foo : String = "Bar" }
defined class Bar
scala> val b = new Bar
b: Bar = Bar@1d2bb9f
scala> b.foo
res0: String = Bar
However, you've asked as to whether it is possible to override an object:
scala> class FooBar {
| object prop extends Foo {
| def foo2 : String = "foo2"
| }
| }
defined class FooBar
scala> val fb = new FooBar
fb: FooBar = FooBar@183d59c
scala> fb.prop.foo
res1: String = Foo
Now for the override:
scala> fb.prop.foo2
res2: String = foo2
scala> class FooBaz extends FooBar {
| override object prop extends Bar {
| def foo2 : String = "bar2"
| }
| }
<console>:8: error: overriding object prop in class FooBar of type object FooBaz.this.prop;
object prop cannot be used here - classes and objects cannot be overridden
override object prop extends Bar {
^
It doesn't really make sense, as how could you ensure that the overridden value also extended Foo?
精彩评论