原书第6版第21章:范型
Chapter 21 Generics
1. (a) will compile fine, but (b) has a compilation error on Line 3, because dates is declared as a list of Date objects. You cannot assign a string to the list.
2. casting is needed in (a), but no casting is necessary in (b) with the generic type ArrayList<Date>.
3. One important benefit is improving reliability and robustness. Potential errors can be detected by the compiler.
4. No.
5. No.
6. Yes.
7. To declare a generic type for a class, place the generic type after the class name, such as GenericStack<E>. To declare a generic type for a method, place the generic type for the method return type, such as <E> void max(E o1, E o2).
8. Bounded generic type such as <E extends AClass> specifies that a generic type must be a subclass of AClass.
9. When you use generic type without specifying an actual parameter, it is called a raw type. GenericStack is roughly equivalent to GenericStack<Object>, but they are not type.
10. ? is unbounded wildcard
? extends T is bounded wildcard
? super T is lower bounded wildcard
11. No. Only ArrayList is loaded.
12. Since all instances of a generic class have the same runtime class, the static variables and methods of a
generic class is shared by all its instances. Therefore, it is illegal to refer a generic type parameter for a class in a static method or initializer.
JAVA程序设计语言基础习... 6页 免费Java语言程序设计基础篇全习题答案23...
Java语言程序设计基础篇全习题答案1_工学_高等教育_教育专区。原书第6版第1章:计算机、程序和Java概述Chapter 1 Introduction to Computers, Programs, and Java ...
Java语言程序设计基础篇课后题答案-Chapter 3 Selection Statements_工学_高等教育_教育专区。Java语言程序设计基础篇课后题答案(英文版)...
Java语言程序设计基础篇 课后答案-机械工业出版社_工学_高等教育_教育专区。Java语言程序设计 基础篇课后答案-机械工业出版社Java语言程序设计 1 / 81 & [编程...
JAVA程序设计语言基础习... 6页 免费java语言程序设计基础篇编程练习题7~...
Java语言程序设计基础篇课后题答案(英文版)...
浙江工业大学软件学院《Java 程序设计》练习题参考答案——赵小敏 自编 版权所有 ... java语言程序设计基础篇... 64页 3下载券 Java语言程序设计[编程练... 45...
JAVA语言程序设计复习题... 46页 免费《Java语言... 淘宝客推广操作基础68份文档 新市场营销法则 助推企业成长 999感冒灵市场营销...
《Java语言程序设计基础教程》习题解答_工学_高等教育_教育专区。java程序设计习题语言程序设计基础教程》 《Java 语言程序设计基础教程》 练习思考题参考答案 2 《...
Java语言程序设计习题答案(清华大学出版杜)张思民版 1-12章答案全_工学_高等...("单词个数 :" + i); } } 第 3 章 面向对象程序设计基础 12 【1】...
热门文档