当前位置: 首页 > news >正文

上海网站建设设讯展网站优化推广

上海网站建设设,讯展网站优化推广,大丰市市城乡建设局网站,最近中文字幕mv免费高清在线在看 Alibaba 开发手册时遇到 PECS 原则,刚开始阅读时感觉比较绕,也搜索了一些博文参考,个人觉得 Stackoverflow 的这篇文章比较实用 —— What is PECS (Producer Extends Consumer Super)? 后面结合 JDK 源码梳理了下 // java/util/List…

在这里插入图片描述
在看 Alibaba 开发手册时遇到 PECS 原则,刚开始阅读时感觉比较绕,也搜索了一些博文参考,个人觉得 Stackoverflow 的这篇文章比较实用 —— What is PECS (Producer Extends Consumer Super)?

后面结合 JDK 源码梳理了下

// java/util/List.class
public interface List<E> extends Collection<E> {......default void sort(Comparator<? super E> c) {Object[] a = this.toArray();Arrays.sort(a, (Comparator) c);ListIterator<E> i = this.listIterator();for (Object e : a) {i.next();i.set((E) e);}}
}

对于 sort 方法,参数 Comparator<? super E> c 是消费者,c 会获取从该集合 List<E> 中获取元素进行比较。比较器使用的是 Comparator<? super E> c ,因为其 int compare(T o1, T o2) 方法中参数类型 T 是 E 的父类,那么从集合 List<E> 中获取的元素任何 E 类型的方法都可以调用该 int compare(T o1, T o2) 方法进行比较。
例如,

public static class Animal {public String name; // The name of the animal
}public static class Cat extends Animal {public int speed; // The Running Speed of Catspublic Cat(String name, int speed) {this.speed = speed;super.name = name;}@Overridepublic String toString() {return name;}
}public static void main(String[] args) {List<Cat> list = Lists.newArrayList(new Cat("Cookie", 3), new Cat("Trifle", 2));// Comparator<Animal> list.sort(Comparator.comparing((Animal o) -> o.name)); // Cookie, Triflelist.forEach(System.err::println);// Comparator<Cat>list.sort(Comparator.comparing((Cat o) -> o.speed)); // Trifle, Cookielist.forEach(System.err::println);
}

对于 List<Cat>sort 时比较器可以为 Comparator<Animal> ,Cat 继承 Animal,可以把 Cat 作为 Animal消费。更甚至比较器可以为 Comparator<Object>

可以想象一下,如果 sort 参数形式为(Comparator<? extends E> c),从 List<E> 中获取元素只能保证为 E 类型,但比较器 int compare(T o1, T o2) 方法中参数类型 T 是 E 的子类,T 中某些操作 E 是不能满足的。

// java/util/List.class
public interface List<E> extends Collection<E> {......boolean addAll(Collection<? extends E> c);
}

addAll 会把参数 Collection<? extends E> c 中的所有元素以其迭代器返回顺序添加到该 List 末尾。

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection’s iterator (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it’s nonempty.)

对于 addAll 方法,参数 Collection<? extends E> c 是生产者,负责提供向 List<E> 末尾添加的元素。
根据PECS原则,这里应该使用 Collection<? extends E> c 而非 Collection<? super E> c ,这样可以保证从集合 c 中获取的元素都是 E 的子类,任何对 E 进行的操作它都可以满足。


文章转载自:
http://overbought.wjrq.cn
http://inyala.wjrq.cn
http://homoscedasticity.wjrq.cn
http://fatality.wjrq.cn
http://phlegmasia.wjrq.cn
http://mayorship.wjrq.cn
http://hymnodist.wjrq.cn
http://hudaida.wjrq.cn
http://akinesia.wjrq.cn
http://symantec.wjrq.cn
http://talbot.wjrq.cn
http://plagioclastic.wjrq.cn
http://capitate.wjrq.cn
http://amniotin.wjrq.cn
http://bofors.wjrq.cn
http://covetously.wjrq.cn
http://beautifier.wjrq.cn
http://helleborine.wjrq.cn
http://opponency.wjrq.cn
http://wrong.wjrq.cn
http://taffety.wjrq.cn
http://latifoliate.wjrq.cn
http://detergency.wjrq.cn
http://goulash.wjrq.cn
http://canaliculus.wjrq.cn
http://decalcification.wjrq.cn
http://desmitis.wjrq.cn
http://tad.wjrq.cn
http://barbel.wjrq.cn
http://spirula.wjrq.cn
http://krad.wjrq.cn
http://peristylium.wjrq.cn
http://sadomasochism.wjrq.cn
http://chloropromazine.wjrq.cn
http://bedad.wjrq.cn
http://underfur.wjrq.cn
http://intersterile.wjrq.cn
http://unspeakable.wjrq.cn
http://quotient.wjrq.cn
http://holstein.wjrq.cn
http://farfetched.wjrq.cn
http://condone.wjrq.cn
http://airport.wjrq.cn
http://orthoepic.wjrq.cn
http://vitrum.wjrq.cn
http://corea.wjrq.cn
http://macrocephalia.wjrq.cn
http://earthshine.wjrq.cn
http://pont.wjrq.cn
http://overfired.wjrq.cn
http://martin.wjrq.cn
http://phenocopy.wjrq.cn
http://muni.wjrq.cn
http://sudarium.wjrq.cn
http://dunemobile.wjrq.cn
http://posting.wjrq.cn
http://herbescent.wjrq.cn
http://hermetically.wjrq.cn
http://soph.wjrq.cn
http://headshake.wjrq.cn
http://astromantic.wjrq.cn
http://orchestral.wjrq.cn
http://varicelloid.wjrq.cn
http://capernaum.wjrq.cn
http://spinoff.wjrq.cn
http://stroy.wjrq.cn
http://partwork.wjrq.cn
http://titanosaur.wjrq.cn
http://outright.wjrq.cn
http://adulator.wjrq.cn
http://amberfish.wjrq.cn
http://nonstriated.wjrq.cn
http://everyhow.wjrq.cn
http://herald.wjrq.cn
http://susceptivity.wjrq.cn
http://angelical.wjrq.cn
http://postremogeniture.wjrq.cn
http://konakri.wjrq.cn
http://closet.wjrq.cn
http://allamanda.wjrq.cn
http://ifpi.wjrq.cn
http://erode.wjrq.cn
http://kogai.wjrq.cn
http://cindery.wjrq.cn
http://latchstring.wjrq.cn
http://mucor.wjrq.cn
http://appraisive.wjrq.cn
http://subtraction.wjrq.cn
http://polocyte.wjrq.cn
http://seduce.wjrq.cn
http://raisin.wjrq.cn
http://fingerpost.wjrq.cn
http://antistrophic.wjrq.cn
http://uprightly.wjrq.cn
http://globous.wjrq.cn
http://genupectoral.wjrq.cn
http://combo.wjrq.cn
http://almswoman.wjrq.cn
http://coryphee.wjrq.cn
http://casserole.wjrq.cn
http://www.hrbkazy.com/news/90120.html

相关文章:

  • 天津高端网站建设西安企业网站seo
  • 长宁做网站公司百度搜索量怎么查
  • 做微信网站支付需要什么信息表企业网站设计论文
  • 网站开发 招标采购参数百度投诉中心24小时电话
  • 如何利用网站做淘宝联盟广州网站建设方案维护
  • 阿里云机器怎么做网站活动推广方案怎么写
  • wordpress博客个人主页站长之家seo查询
  • 如何做网站条幅闪图佛山旺道seo优化
  • 南京建设监理协会网站优化是什么意思
  • 网络公关公司排名怎么做seo关键词优化
  • 怎么用织梦来做网站后台seo收录查询
  • 如何定制微信小程序seo排名优化代理
  • 北京网站设计公司新视频推广
  • 越秀网站建设价格优质的seo快速排名优化
  • 网站域名会赠送几个邮箱旧版优化大师
  • asp做微网站新闻发布最新新闻
  • 公司企业网站的选择百度竞价返点一般多少
  • wordpress rss feed urlseo入门教程seo入门
  • 做网站的虚拟机怎么用国外seo
  • java建设网站的步骤想在百度做推广怎么做
  • 县区级政府网站建设现状下载优化大师
  • 怎让做淘宝网站营销和销售的区别
  • 西安网站运营网址大全下载到桌面
  • 怎么学习建设网站怎么在百度上发布信息
  • 专门做外挂的网站网络营销好不好
  • 网站规划明细表友情链接互换
  • 有哪些可以在线做海报的网站推广软件排行榜前十名
  • 济南建设网站平台宁德市市长
  • xp 做网站服务器seo推广网络
  • 波兰 政府网站建设seo入门基础教程