石建 | 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,從細節中尋找不斷的成長點
          主站蜘蛛池模板: 枞阳县| 土默特右旗| 永济市| 谷城县| 上栗县| 格尔木市| 龙岩市| 青铜峡市| 浦东新区| 聊城市| 上饶县| 弥渡县| 永胜县| 旬邑县| 罗定市| 蒙城县| 磐安县| 沁水县| 巩留县| 稻城县| 金华市| 花莲市| 连州市| 鄂伦春自治旗| 深水埗区| 灵石县| 扶沟县| 农安县| 曲松县| 锦州市| 来宾市| 左权县| 济阳县| 仁寿县| 潼关县| 银川市| 陕西省| 久治县| 从江县| 彭山县| 内乡县|