標籤:java tutorials_gener
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是非常棘手的問題,他們不總立即是出現在表面,當它們啟動並執行時候可能,在程式的啟動並執行時候的出現的那一點問題早已偏離了實際問題的原因
泛型給你的代碼添加的健壯性通過做更多編譯時間檢查,在學習這節課之後,你可能相應會一探究竟探究泛型指南手冊
Java Tutorials_Generics(java泛型)