How to add listener on ArrayList in java

前端 未结 3 740
予麋鹿
予麋鹿 2020-12-06 18:56

I want to create my own implementation of ArrayList in java, that can listen when the list is changing and to do action when this happens. From what I have read, I understan

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 19:39

    the resp. ;)

    private class MyList extends ArrayList {
    
          @Override
          public void sort(Comparator c) {
            super.sort(c); 
            resetLancamentos(); // call some metod ;)
          }
        //...
         @Override
         public boolean removeAll(Collection c) {
            //To change body of generated methods, choose Tools | Templates.
            boolean ret = super.removeAll(c);
            resetLancamentos(); // some metod like fireObjChanged() will do the job too
             return ret;
         }
    
    }
    

提交回复
热议问题