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

  • 27
  • 0
  • 约5.95万字
  • 约 35页
  • 2019-01-06 发布于浙江
  • 举报

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

21 Generics 第 章 泛型 wildcard通配符 ? unboundedwildcard 非受限通配符 ?extendsT boundedwildcard 受限通配符 ?superT lowerboundwildcard 下限通配符 泛型是参数化类型的能力。 T表示形式泛型类型,后面可以用一个实际具体类型代替它。 泛型类型必须是引用类型 受限泛型类型boundedwildcard public static void main(String[] args ) { Rectangle rectangle new Rectangle(2, 2); Circle9 circle new Circle9(2); System.out.println(Same area? + equalArea(rectangle, circle)); } public static E extendsGeometricObject boolean equalArea(E obj ect 1, E obj ect2) { return obj ect 1.findArea() obj ect2.findArea(); } Raw Type is Unsafe :GenericStack stack new GenericStack(); // 原始类型 Make it safe :GenericStackObj ect stack new GenericStackObj ect(); It is important to note that a generic class is shared by all its instances regardless of its actual generic type. 不管实际的具体类型是什么,一个泛型是由其所有实例共享的. GenericStackString stack 1 new GenericStackString(); GenericStackInteger stack2 new GenericStackInteger(); Although GenericStackString and GenericStackInteger are two types, but there is only one class GenericStack loaded into the JVM. GenericStackString GenericStackInteger , 尽管 和 是两种类型 但是只有一 个 GenericStack 类加载到 JVM. 22 Javacollectionframework 第 章 集合构架 A collection is a container obj ect that represents a group of obj ects, often referred to as elements. The Java Collections Framework supports three types of collections, named sets, lists, andmaps. Set and List are subinterfaces of Collection. The Set interface extends the Collection interface. It does not introduce new methods or constants, but it stipulates 保证 that an instance of Set contains no duplicate 重复 的elements. The concrete classes 具体类that implement Set must ensure that no duplicate 重复的 elements can be added to the set. That is no two elements e1 and e2 can be in the set such that e1.equal

文档评论(0)

1亿VIP精品文档

相关文档