陳俊良臺灣大學:資訊工程學研究所鄭力瑋Cheng, Li-WeiLi-WeiCheng2007-11-262018-07-052007-11-262018-07-052006http://ntur.lib.ntu.edu.tw//handle/246246/53872經過多年的研究,一個將Java語言加入泛型機制的解法已經在Java 5.0上發佈了。為了兼顧新舊版本的相容性以及新舊程式碼的交互使用,Sun採用了擦拭法來達成泛型機制。擦拭法通常也被稱為一般化方法。然而,在擦拭法下帶來最大的問題為執行期間與泛型相關的型別資訊將會漏失。本論文中,將提出擦拭法帶來的另一個問題,這問題將導致無法使用泛型的靜態成員。最後,提出一個可行的解法並實現於Java 5.0編譯器之上。Through the research for many years, a solution for the problem of extending Java with parametric polymorphism (genericity) has released in Java 5.0. In order to have the capability of backward compatibility and the capability of interoperability with legacy code, Sun adopts the method of type erasure to achieve Java with parametric polymorphism. The method is also called Generalization. Run-time type information will be lost because of type erasure and it’s the major problem of the solution. In the thesis, we show that Java 5.0 can’t declare static variable whose type is type parameter of class due to type erasure and propose a solution for this problem.中文摘要 i Abstract iii 致謝 v 目錄 vii 圖表目錄 ix 表格目錄 xi 1. 簡介 1 1.1. 研究動機 1 1.2. 相關研究 2 1.3. 論文架構 3 2. 泛型 5 2.1. 關於泛型的一些背景知識 6 2.2. Generalization 8 2.3. Specialization 9 2.4. Specialization and sharing 10 2.5. 泛型爪哇(Generic Java) 12 2.5.1. 目標 13 2.5.2. 型別擦拭(Type erasure) 14 2.6. 結論 15 3. 問題及策略 17 3.1. 一般化方法於擦拭法下引起的問題 17 3.2. 策略 20 4. 實作 25 4.1. Java 編譯器 25 4.1.1. Java的演進歷史 25 4.1.2. Java編譯器的內部結構 28 4.2. 設計流程 30 4.3. 轉換步驟 32 4.3.1. Helper Class 33 4.3.2. SGV attribute and SGM attribute 36 4.3.3. 轉換過程 39 4.3.4. 結論 46 5. 結論 47 參考文獻 49 A. 實驗結果 53 A1. Test Case 1 53 A2. Test Case 2 61 A3. Test Case 3 68 A4. Test Case 4 71 A5. 結論 74968801 bytesapplication/pdfen-US泛型一般化特殊化一般化及共享爪哇編譯器GenericsGeneralizationSpecializationSpecialization and sharingJava CompilerJava語言靜態泛型成員之機制A Mechanism of Static Generic Type Members for the Java Programming Languagethesishttp://ntur.lib.ntu.edu.tw/bitstream/246246/53872/1/ntu-95-R93922096-1.pdf