I.Anchev
I.Anchev

Reputation: 93

Invoking interface object methods

I have a interface Appendable in which I have a method appendTo(Appendable obj). Classes TextMessage and EncMessage extend class Message, which implements Appendable.In TextMessage I have to implement method appendTo(Appendable obj) so that if obj is an instance of TextMessage the method is supposed to change its data members. But I can't access TextMessage set methods.So my question is how can I access and use them?

Upvotes: 0

Views: 46

Answers (1)

Eran
Eran

Reputation: 393821

You could implement appendTo of TextMessage like this :

void appendTo (Appendable obj) {
  if (obj instanceof TextMessage) {
    TextMessage msg = (TextMessage) obj;
    msg.setXXX (...);
    ...
  }
}

I had to make some assumptions without actually seeing your code.

Upvotes: 2

Related Questions