The Java™ Tutorials —— Generics:前言
2016-01-25 17:16
295 查看
The Java™ Tutorials —— Generics:前言
原文地址:https://docs.oracle.com/javase/tutorial/java/generics/index.html
关键点
泛型可以增强编译时错误检测,减少因类型问题引发的运行时异常
全文翻译
In any nontrivial software project, bugs are simply a fact of life. Careful planning, programming, and testing can help reduce their pervasiveness, but somehow, somewhere, they’ll always find a way to creep into your code. This becomes especially apparent asnew features are introduced and your code base grows in size and complexity.
在任何平常的软件工程中,bug不过就是生活中的一种事实。仔细地规划、编码以及测试可以帮助你减少它们的遍及范围。但是不知何处,也不知何时,这些bug总会找到一种方式逐渐入侵到你的代码中。尤其是当新特性推出后,而你的代码库却越来越大,越来越复杂时,bug的问题就会更加凸显。
Fortunately, some bugs are easier to detect than others. Compile-time bugs, for example, can be detected early on; you can use the compiler’s error messages to figure out what the problem is and fix it, right then and there. Runtime bugs, however, can be much
more problematic; they don’t always surface immediately, and when they do, it may be at a point in the program that is far removed from the actual cause of the problem.
不过幸运的是,有一些bug比其他bug更加容易去检测。例如,编译时的bug就可在早期被检测到;你可利用计算机的错误提示查明问题,并在此时对出错的地方进行修改。然而,运行时错误更成问题;它们并非总是立刻浮现,当它们出现时,程序很可能就处在某种状态中,而这种状态却与触发问题的实际原因大相径庭。
Generics add stability to your code by making more of your bugs detectable at compile time. After completing this lesson, you may want to follow up with the Generics tutorial by Gilad Bracha.
泛型会为你的代码增加稳定性。它会在编译时让你的bug更容易被侦测出来。在完成本课时后,你也许会想阅读下Gilad Bracha编写的《泛型指南》。
下一节:Why Use Generics?
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树