欢迎来到天天文库
浏览记录
ID:38592130
大小:677.50 KB
页数:35页
时间:2019-06-15
《面向对象程序设计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();AlthoughGenericStackandGenericStack4、teger>aretwotypes,butthereisonlyoneclassGenericStackloadedintotheJVM.尽管GenericStack和GenericStack是两种类型,但是只有一个GenericStack类加载到JVM.第22章集合构架JavacollectionframeworkAcollectionisacontainerobjectthatrepresentsagroupofobjects,oftenreferredtoaselements.TheJavaCollectionsFramewo5、rksupportsthreetypesofcollections,namedsets,lists,andmaps.SetandListaresubinterfacesofCollection.TheSetinterfaceextendstheCollectioninterface.Itdoesnotintroducenewmethodsorconstants,butitstipulates保证thataninstanceofSetcontainsnoduplicate重复的elements.Theconcreteclasses具体类thatimplementSet6、mustensurethatnoduplicate重复的elementscanbeaddedtotheset.Thatisnotwoelementse1ande2canbeinthesetsuchthate1.equals(e2)istrue.set规则集中元素互异,不得重复。TheAbstractSetclassisaconvenienceclassthatextendsAbstractCollectionandimplementsSet.TheHashSetclassisaconcreteclassthatimplementsSet.HashSet类是一个实现S7、et接口的具体类。Itcanbeusedtostoreduplicate-freeelements.可以存储互不相同的元素Forefficiency,objectsaddedtoahashsetneedtoimplementthehashCodemethodinamannerthatproperlydispersesthehashcode.添加到散列集中的对象必须实现hashCode方法,适当地散列分布散列码。for(Objectelement:set)System.out.print(element.toString()+"");SortedSetisasub
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
此文档下载收益归作者所有