Java Tutorials_Generics(java泛型)

Lesson: Generics (Updated)

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.

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.

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.

Java泛型

在任何琐碎的软件项目中,bugs是一个简单的生活事实。你小心的计划,编程,并且加以测试能够帮助你减少普通的错误,但是不管怎样,也不论在哪些地方,这些bugs总会寻找一个方式浸入进你的代码,当你新的功能特性被引入和你的代码在数量和复杂的增长的时候是尤其的明显。

幸运的是,有一些代码是更容易被检测到比起其他的代码,例如:编译时的bugs在早期就能够被检测到,你能够利用编译的错误信息去思考问题出现在哪儿,并且修复他们,然后,运行时的bugs是非常棘手的问题,他们不总立即是出现在表面,当它们运行的时候可能,在程序的运行的时候的出现的那一点问题早已偏离了实际问题的原因

泛型给你的代码添加的健壮性通过做更多编译时检查,在学习这节课之后,你可能相应会一探究竟探究泛型指南手册


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。