码迷,mamicode.com
首页 > 其他好文 > 详细

泛型里的super和extend

时间:2017-05-29 00:24:49      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:解释   生产者   cer   cti   code   ext   ons   producer   should   

<? extends T>和<? super T>应该怎么用?

 

网上看到一些比较难懂的回答,但是在EffectiveJava(2th Edition)遇到简单明了的解释:

If your parameter is a producer, it should be <? extends T>, if it‘s a consumer it has to be <? super T>

即,做生产者的方法的参数用extends,消费者的方法的参数用super。

 

这里翻译一下:

<? extends T> 为 T的某个子类型 的 类

<? super T> 为 T的某种超类 的 类

 

泛型里的super和extend

标签:解释   生产者   cer   cti   code   ext   ons   producer   should   

原文地址:http://www.cnblogs.com/771k/p/6916997.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!