Java anonymous override doesn't work
I am currently experiencing a weird issue with anonymous method override
and inherits. It's difficult to explain clearly, so to begin with here is
a representation of my code :
public abstract class A {
public void draw() {
someAction();
}
}
public class B {
// Other methods
}
ArrayList< A > listA = new ArrayList< A >();
B objectB = new B() {
@Override
public void draw() {
someActionOverriden();
}
}
listA.add( objectB );
for( A item : listA ) {
item.draw();
}
The thing is : the draw() method that is override anonymously is never
called. I presume this may be because "item" is of class A, and so it
never goes to the anonymous method, but is there a way to implement this
kind of design?
No comments:
Post a Comment