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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.