石建 | Fat Mind

          泛型 [core Java 閱讀筆記]


          題記:單元測試的過程中,遇到泛型mock的問題;重新溫習一遍,閱讀(core java 泛型)



          xmind格式(可下載) :整理過程中,記錄為xmind格式

          單元測試遇到的問題,簡化后如下:

           1     public List<? extends Date> getDateT() {
           2         return null;
           3     }
           4     public List<Date> getDate() {
           5         return null;
           6     }
           7     public void mockGetDate() {
           8         TestMain main = mock(TestMain.class);
           9         when(main.getDate()).thenReturn(new ArrayList<Date>()); //編譯OK
          10         /*
          11          * The method thenReturn(List<capture#2-of ? extends Date>) in the type 
          12          * OngoingStubbing<List<capture#2-of ? extends Date>>
                           is not applicable for the arguments (ArrayList<Date>)
          13          */
          14         when(main.getDateT()).thenReturn(new ArrayList<Date>()); //編譯錯誤
          15         when(main.getDateT()).thenReturn(new ArrayList<Timestamp>()); //編譯錯誤
          16         when(main.getDateT()).thenReturn(new ArrayList<Object>()); //編譯錯誤
          17         when(main.getDateT()).thenReturn(new ArrayList()); //編譯OK
          18     }

          仍沒理解,哪位大仙,能幫我解釋下 ?

          posted on 2012-03-08 21:05 石建 | Fat Mind 閱讀(336) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          <2012年3月>
          26272829123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          What 、How、Why,從細節中尋找不斷的成長點
          主站蜘蛛池模板: 阳曲县| 中方县| 海安县| 米易县| 满城县| 义马市| 桃源县| 日喀则市| 遂川县| 都兰县| 阳泉市| 吉安县| 上饶县| 宁化县| 安多县| 元朗区| 神池县| 铁岭市| 南丰县| 托克托县| 东明县| 古丈县| 东乡县| 广灵县| 台湾省| 襄樊市| 华容县| 准格尔旗| 武威市| 张家界市| 科尔| 双桥区| 阿尔山市| 邓州市| 隆林| 石狮市| 荣成市| 安陆市| 井陉县| 通河县| 金沙县|