1. Raw types behave as if all of the generic type information were erased from the type declaration. For all practical purposes, the raw type List behaves the same way as the interface type List did before generics were added to the platform.
2. It pays to discover errors as soon as possible after they are made, ideally at compile time. By using raw types, you don’t discover the error till runtime, long after it has happened, and in code that is far removed from the code containing the error. Once you see the ClassCastException, you have to search through the code base looking for the method invocation that put the wrong type into the collection.
3. If you use raw types, you lose all the safety and expressiveness benefits of generics.
4. It was deemed critical that all of legacy codes remain legal and interoperable with new code that does use generics. It had to be legal to pass instances of parameterized types to methods that were designed for use with ordinary types, and vice versa. This requirement, known as migration compatibility, drove the decision to support raw types.
5. List<String> is a subtype of the raw type List, but not of the parameterized type List<Object>. As a consequence, you lose type safety if you use a raw type like List, but not if you use a parameterized type like List<Object>.
Commented By Sean:You can assign a List<String> to List and add anything to it through List, but you cann’t assign List<String> to List<Object>.
6. You can’t put any element (other than null) into a Collection<?> and you can’t assume anything about the type of the objects that you get out.
7. There are two minor exceptions to the rule that you should not use raw types in new code, both of which stem from the fact that generic type information is erased at runtime. First, you must use raw types in class literals. (Though it does permit array types and primitive types.) Second, it is illegal to use the instanceof operator on parameterized types other than unbounded wildcard types. The use of unbounded wildcard types in place of raw types does not affect the behavior of the instanceof operator in any way.
相关推荐
Item 26: Don’t use raw types Item 27: Eliminate unchecked warnings Item 28: Prefer lists to arrays Item 29: Favor generic types Item 30: Favor generic methods Item 31: Use bounded wildcards to ...
// Distribute and change freely, except: don't remove my name from the source // // No warrantee of any kind, express or implied, is included with this // software; use at your own risk, ...
本文档标题所提到的“DON’T USE LARGE MINI-BATCHES, USE LOCAL SGD”指向的是关于分布式训练中使用局部随机梯度下降(Stochastic Gradient Descent,SGD)的一个重要观点。传统的SGD方法在处理大规模深度神经网络...
Unit4 Don't eat in class
- 不要在教室或走廊听音乐:`Don’t listen to music in the classrooms or the hallways.` - 不要打架:`Don’t fight.` - 不要戴帽子:`Don’t wear a hat.` #### 2. 可以行为 - 可以在音乐室内听音乐:`Listen ...
course don't load course don't load course don't load course don't load
- 不要在教室打篮球:Don't play basketball in the classroom. 通过预习,可能存在的疑问可能包括祈使句的具体应用,"must"和"have to"/"needn't"的区别,以及"arrive"和"be late for"的用法差异。此外,对于...
### You Don't Know JS - Types & Grammar #### 核心概念与基础知识 《You Don't Know JS - Types & Grammar》是一本深入探讨JavaScript基础类型的书籍,由Kyle Simpson编写。本书旨在帮助读者理解JavaScript的...
Matplotlib makes it easy to generate plots, histograms, power spectra, bar charts, error charts, and other kinds of plots, with just a few lines of code. Interactive Applications Using Matplotlib will...
As part of the "You Don't Know JS" series, this concise yet in-depth guide focuses on new asynchronous features and performance techniques—including Promises, generators, and Web Workers—that let ...
If getting started with this new framework sounds difficult and time-consuming, don’t worry, we’ve got you covered. ARKit by Tutorials helps you learn ARKit the quick and easy way: by following fun...
【Unit 4 "Don’t eat in class" 学案预习稿】 本单元主要学习与校园规则相关的词汇和表达,旨在帮助学生熟练掌握并运用这些关键的英语词汇和语句。学习目标包括: 1. 掌握核心词汇:rule(规则)、arrive(到达)...
Don’t hire a software developer until you read this book By 作者: K.N. Kukoyi ISBN-10 书号: 1539188191 ISBN-13 书号: 9781539188193 Edition 版本: 1 出版日期: 2017-05-26 pages 页数: 422 Use the ...
Don’t Make Me Think田士庆
在众多单元中,“七下Unit 4 Don't eat in class”是一堂集语言学习和规则教育于一体的重要课程。为了检验学生对这个单元的掌握程度,一份详尽的测试题应运而生,即《七下Unit 4 Don't eat in class测试题及答案含...
《不要让我思考》这本书是Web设计领域的一部经典之作,作者是Steve Krug。书中提出了许多关于网页设计的基本原则,这些原则对于设计师、产品经理、网页开发者等从事与Web界面设计相关工作的专业人士具有极大的指导...