面向对象程序设计JAVA进阶版重点整理

面向对象程序设计JAVA进阶版重点整理

ID:38592130

大小:677.50 KB

页数:35页

时间:2019-06-15

面向对象程序设计JAVA进阶版重点整理_第1页
面向对象程序设计JAVA进阶版重点整理_第2页
面向对象程序设计JAVA进阶版重点整理_第3页
面向对象程序设计JAVA进阶版重点整理_第4页
面向对象程序设计JAVA进阶版重点整理_第5页
资源描述:

《面向对象程序设计JAVA进阶版重点整理》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、第21章泛型Genericswildcard通配符?unboundedwildcard非受限通配符?extendsTboundedwildcard受限通配符?superTlowerboundwildcard下限通配符泛型是参数化类型的能力。表示形式泛型类型,后面可以用一个实际具体类型代替它。泛型类型必须是引用类型受限泛型类型boundedwildcardpublicstaticvoidmain(String[]args){Rectanglerectangle=newRectangle(2,2);Circle9circle=newCircle9(2);Syste

2、m.out.println("Samearea?"+equalArea(rectangle,circle));}publicstaticbooleanequalArea(Eobject1,Eobject2){returnobject1.findArea()==object2.findArea();}RawTypeisUnsafe:GenericStackstack=newGenericStack();//原始类型Makeitsafe:GenericStackstack=newGenericStack<

3、Object>();Itisimportanttonotethatagenericclassissharedbyallitsinstancesregardlessofitsactualgenerictype.不管实际的具体类型是什么,一个泛型是由其所有实例共享的.GenericStackstack1=newGenericStack();GenericStackstack2=newGenericStack();AlthoughGenericStackandGenericStack

4、teger>aretwotypes,butthereisonlyoneclassGenericStackloadedintotheJVM.尽管GenericStack和GenericStack是两种类型,但是只有一个GenericStack类加载到JVM.第22章集合构架JavacollectionframeworkAcollectionisacontainerobjectthatrepresentsagroupofobjects,oftenreferredtoaselements.TheJavaCollectionsFramewo

5、rksupportsthreetypesofcollections,namedsets,lists,andmaps.SetandListaresubinterfacesofCollection.TheSetinterfaceextendstheCollectioninterface.Itdoesnotintroducenewmethodsorconstants,butitstipulates保证thataninstanceofSetcontainsnoduplicate重复的elements.Theconcreteclasses具体类thatimplementSet

6、mustensurethatnoduplicate重复的elementscanbeaddedtotheset.Thatisnotwoelementse1ande2canbeinthesetsuchthate1.equals(e2)istrue.set规则集中元素互异,不得重复。TheAbstractSetclassisaconvenienceclassthatextendsAbstractCollectionandimplementsSet.TheHashSetclassisaconcreteclassthatimplementsSet.HashSet类是一个实现S

7、et接口的具体类。Itcanbeusedtostoreduplicate-freeelements.可以存储互不相同的元素Forefficiency,objectsaddedtoahashsetneedtoimplementthehashCodemethodinamannerthatproperlydispersesthehashcode.添加到散列集中的对象必须实现hashCode方法,适当地散列分布散列码。for(Objectelement:set)System.out.print(element.toString()+"");SortedSetisasub

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。