dynamic - java polymorphism not working, what am I missing? -


i have following hierarchy in project:

public abstract class abstractmessage extends abstractentity{} public class parsefailedmessage extends abstractmessage {} public class subparsedfailedmessage extends parsefailedmessage {} 

i have following methods:

public abstractmessage dohandle(abstractmessage messagetohandle) {     //preparetohandle(messagetohandle);     handle(messagetohandle);     //finalize(messagetohandle);     return messagetohandle;  }  @transactional(readonly = false) private void handle(parsefailedmessage message) {     message.sethandled(false);  }  @transactional(readonly = false) private void handle(abstractmessage message) {     message.sethandled(true);  } 

for reason when call dohandle(new subparsedfailedmessage()) function being called handle(abstractmessage msg) , not handle(subparsedfailedmessage msg) emphasized text expecting..

can why polymorphism not working here?

dohandle declared receive parameter of type abstractmessage. means when code compiled, code generated call handle() generated call handle(abstractmessage), rather handle(parsefailedmessage).

if still want function called according dynamic type of object, should make function member of subparsedfailedmessage, , call messagetohandle.handle(). looks more oop-like, , therefore preferred.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -