概述
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 as new 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?
最后
以上就是炙热钢笔为你收集整理的The Java™ Tutorials —— Generics:前言 The Java™ Tutorials —— Generics:前言的全部内容,希望文章能够帮你解决The Java™ Tutorials —— Generics:前言 The Java™ Tutorials —— Generics:前言所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复