中文版書中的問題代碼記錄:
只記錄了P213后面的錯誤代碼,如果后面發(fā)現(xiàn)P213頁前面的錯誤代碼,會繼續(xù)補齊。但我提供的代碼都是可以正常運行的,如果有使用者發(fā)現(xiàn)中文版書中其他的錯誤代碼請告訴我,方便我在這里補齊,謝謝。
P213,重構(gòu)代碼有誤,作者在源代碼中提供的正確代碼如下:
public ShootingGalleryTargetRow(Image sprite, int value) {
targetValue = value;
newTargetTicker = 0;
this.sprite = (BufferedImage)sprite;
}
P220,函數(shù)中的System.exit(1)因為前面拋出了異常,所以永遠無法執(zhí)行,直接刪除。
public Image getSpriteBySize(int size) {
...
throw new IllegalArgumentException("Unknown Sprite Size: " + size);
System.exit(1);
...
}
P250,使用泛型GenericRole<String, String>未定義類型。
public class GenericRoleProgram {
public static void main(String[] args) {
LinkedList<GenericRole<String,String>> roleMap=new LinkedList<GenericRole<String, String>>();
...
}
原作者的代碼,我自己輸入和做了部分修改的代碼。