石建 | 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 阅读(316) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

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

统计

常用链接

留言簿

随笔分类

随笔档案

搜索

最新评论

What 、How、Why,从细节中寻找不断的成长点