D
danieleloff
The curious thing about Java is when I override a method in a derived
class, the overridden method is called in the base class. I'm hoping
this is somehow my mistake, as I'm new to Java and I cannot imagine why
anyone would do this, but it seems like the behaviour I'm witnessing.
That's a misfeature in my mind, because the base class cannot expect to
use methods from a derived class (especially before said class has been
constructed) and have them function as expected.
My dilema is this:
I called an accessor method in the constructor of my base class to set
a value. I created a derived class that overrides this method to add an
upper-bounds check. When I call the base class constructor using
super() the upper bound member is not yet initialized, and is the
default 0. The base class then calls the overridden method to set the
value, the upper bound is zero and the value is clipped to 0 regardless
of what it was. This is obviously not the desired behaviour!
Is my interpretation of what's happening correct? If so what's the
'Java' way of dealing with it?
Thanks,
-Dan
class, the overridden method is called in the base class. I'm hoping
this is somehow my mistake, as I'm new to Java and I cannot imagine why
anyone would do this, but it seems like the behaviour I'm witnessing.
That's a misfeature in my mind, because the base class cannot expect to
use methods from a derived class (especially before said class has been
constructed) and have them function as expected.
My dilema is this:
I called an accessor method in the constructor of my base class to set
a value. I created a derived class that overrides this method to add an
upper-bounds check. When I call the base class constructor using
super() the upper bound member is not yet initialized, and is the
default 0. The base class then calls the overridden method to set the
value, the upper bound is zero and the value is clipped to 0 regardless
of what it was. This is obviously not the desired behaviour!
Is my interpretation of what's happening correct? If so what's the
'Java' way of dealing with it?
Thanks,
-Dan