4 Replies Latest reply on Mar 30, 2009 4:22 AM by 807588

    Generic implements

    807588
      Hi, Is it possible to allow only classes that implement a certin interface in a generic class.

      import java.awt.event.*;

      public class ButtonListener<T> implements ActionListener {
      private T t;

      public ButtonListener(T t){
      this.t = t;
      }

      public void actionPerformed(ActionEvent evt){
      t.doaction(evt);
      }
      }

      But only classes that implent the PerformedAction interface are allowed to be passed to the class as T.

      So in other words T must implement PerformedAction.

      Cheers

      Cam