石建 | 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 閱讀(340) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

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

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          What 、How、Why,從細節中尋找不斷的成長點
          主站蜘蛛池模板: 横山县| 阿克| 阿荣旗| 铜鼓县| 辛集市| 花垣县| 留坝县| 黎川县| 惠安县| 林芝县| 时尚| 北宁市| 双桥区| 平山县| 偏关县| 尼勒克县| 武川县| 绥中县| 大兴区| 疏附县| 田阳县| 建始县| 南昌市| 黄平县| 全椒县| 西乌| 潮州市| 桦甸市| 万宁市| 图们市| 石泉县| 余姚市| 吴旗县| 禹州市| 雅安市| 呼图壁县| 榆树市| 威海市| 阳西县| 丹棱县| 墨脱县|