The Java™ Tutorials —— Generics:前言

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?


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值