multiple inherited (implements) with generics classes
multiple inherited with generics classes
May 1, 2007 11:04 AM
Click to email this message Click to edit this message...
Hello all, here is my generic observer/ subject code.
package jstock;
/**
*
* @author yccheok
*/
public interface Observer<S, A> {
public void update(S subject, A arg);
}
public class Subject<S, A> {
public void attach(Observer<S, A> observer) {
observers.add(observer);
}
void notify(S subject, A arg) {
for (Observer<S, A> obs : observers) {
obs.update(subject, arg);
}
}
private List<Observer<S, A>> observers = new
CopyOnWriteArrayList<Observer<S, A>>();
}
However, when I try to implements more than one class (single class
only is ok), I get the following error :
/home/yccheok/Projects/jstock/src/org/yccheok/jstock/gui/
MainFrame.java:40: org.yccheok.jstock.engine.Observer cannot be
inherited with different arguments:
<org.yccheok.jstock.engine.RealTimeStockMonitor,java.util.List<org.yccheok.jstock.engine.Stock>>
and
<org.yccheok.jstock.engine.StockHistoryMonitor,org.yccheok.jstock.engine.StockHistoryServer>
public class MainFrame extends javax.swing.JFrame implements
Here is the code which I am implementing the generic classes.
public class MainFrame extends javax.swing.JFrame implements
org.yccheok.jstock.engine.Observer<RealTimeStockMonitor,
java.util.List<org.yccheok.jstock.engine.Stock>>,
org.yccheok.jstock.engine.Observer<StockHistoryMonitor,
StockHistoryServer>
May I know how I can avoid the error message?
Thank you.
cheok